Skip to content

Commit 9c508c3

Browse files
committed
Corrected elseifs conditions
1 parent 0c33d75 commit 9c508c3

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;
1111

1212
use function array_search;
13+
use function current;
14+
use function end;
1315
use function max;
1416
use function range;
17+
use function reset;
1518
use PhpParser\Node;
1619
use PhpParser\NodeVisitorAbstract;
1720

@@ -85,6 +88,14 @@ public function enterNode(Node $node): void
8588
);
8689
$contentEnd = $endLine;
8790

91+
end($node->stmts);
92+
$lastNode = current($node->stmts);
93+
reset($node->stmts);
94+
95+
if ($lastNode instanceof Node\Stmt\Nop) {
96+
$contentEnd = $lastNode->getEndLine() + 1;
97+
}
98+
8899
if (1 > ($contentEnd - $contentStart)) {
89100
return;
90101
}

tests/_files/source_for_branched_exec_lines.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,3 @@ public function withIfElseifElse() // +5
142142
} // -12
143143
} // 0
144144
}
145-
146-
//$myClass = new MyClass();
147-
//foreach (get_class_methods($myClass) as $method) {
148-
// $myClass->{$method}();
149-
//}

tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testExecutableLinesAreGroupedByBranch(): void
4444
$branch = 0;
4545

4646
foreach ($linesFromSource as $lineNumber => $line) {
47-
if (1 !== preg_match('#^[^/].+// (?<branchIncrement>[+-]?\d+)$#', $line, $matches)) {
47+
if (1 !== preg_match('#^\s*[^/].+// (?<branchIncrement>[+-]?\d+)$#', $line, $matches)) {
4848
continue;
4949
}
5050

0 commit comments

Comments
 (0)