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)
| 652 | /// echo $first->name; |
| 653 | /// ``` |
| 654 | fn 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 |
no test coverage detected