diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php index 84e7bde7f..548243140 100644 --- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php +++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php @@ -175,7 +175,7 @@ public function enterNode(Node $node): void ); if ($hasEmptyBody) { - if ($node->getEndLine() === $node->getStartLine()) { + if ($node->getEndLine() === $node->getStartLine() && isset($this->executableLinesGroupedByBranch[$node->getStartLine()])) { return; } diff --git a/tests/_files/source_for_branched_exec_lines.php b/tests/_files/source_for_branched_exec_lines.php index f7d8106f9..936ea018e 100644 --- a/tests/_files/source_for_branched_exec_lines.php +++ b/tests/_files/source_for_branched_exec_lines.php @@ -460,12 +460,18 @@ public function myMethod() { return; // +3 } - } // -3 + + public function m1(): void {} // +1 + public function m2(): void { + } // +1 + public function m3(): void + {} // +1 + } // -6 ; // 0 } public function withComments() { - $var = 1; // +4 + $var = 1; // +7 /** @var int $var */ $var = 2; // +1 // C3 @@ -582,7 +588,7 @@ public function multilineVoid( trait MyTrait { public function myTrait() - {} // +5 + {} // +6 } abstract class MyAbstractClass implements MyInterface @@ -594,7 +600,12 @@ final class MyFinalClass extends MyAbstractClass 'foo' => 'bar', ]; private string $var; - public function myMethod(): void + public function m1(): void {} // +4 + public function m2(): void { + } // +1 + public function m3(): void + {} // +1 + public function m4(): void { - } // +4 -} \ No newline at end of file + } // +1 +} diff --git a/tests/_files/source_for_branched_exec_lines_php81.php b/tests/_files/source_for_branched_exec_lines_php81.php index 97f446751..846b62c45 100644 --- a/tests/_files/source_for_branched_exec_lines_php81.php +++ b/tests/_files/source_for_branched_exec_lines_php81.php @@ -37,7 +37,7 @@ public function neverReturn(): never; class NewInInit_NoInit { public function __construct(private DateTimeInterface $dateTime) { - } // +1 + } // +3 public function noinit(DateTimeInterface $dateTime) { } // +1 }