MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / ends_with_output

Function ends_with_output

src/code_actions/extract_function.rs:654–678  ·  view source on GitHub ↗

Check whether the body *ends* with one or more output statements but also contains non-output setup lines (assignments, calls, etc.). This catches the common "compute then display" pattern: ```php $first = $users->first(); echo $first->name; ```

(body: &str)

Source from the content-addressed store, hash-verified

652/// echo $first->name;
653/// ```
654fn ends_with_output(body: &str) -> bool {
655 let trimmed = body.trim();
656 if trimmed.is_empty() {
657 return false;
658 }
659
660 let lines: Vec<&str> = trimmed
661 .lines()
662 .map(|l| l.trim().trim_end_matches(';').trim())
663 .filter(|l| !l.is_empty() && !l.starts_with("//") && !l.starts_with('#'))
664 .collect();
665
666 if lines.len() < 2 {
667 return false;
668 }
669
670 // The last line must be output.
671 if !is_output_line(lines[lines.len() - 1]) {
672 return false;
673 }
674
675 // At least one earlier line must NOT be output (otherwise
676 // `is_pure_output` already matched).
677 lines[..lines.len() - 1].iter().any(|l| !is_output_line(l))
678}
679
680/// Detect when the body is a single method call or function call
681/// statement (no assignment, no return). Returns a name derived from

Callers 1

derive_base_nameFunction · 0.85

Calls 5

is_output_lineFunction · 0.85
filterMethod · 0.80
iterMethod · 0.80
is_emptyMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected