Skip to content

Commit 02eac9f

Browse files
Slamdunksebastianbergmann
authored andcommitted
Added goto
1 parent 44b50ee commit 02eac9f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,18 @@ public function enterNode(Node $node): void
141141
if (
142142
$node instanceof Node\Stmt\Return_ ||
143143
$node instanceof Node\Stmt\Continue_ ||
144-
$node instanceof Node\Stmt\Break_
144+
$node instanceof Node\Stmt\Break_ ||
145+
$node instanceof Node\Stmt\Goto_ ||
146+
$node instanceof Node\Stmt\Label
145147
) {
146148
$returnBranch = $this->executableLinesGroupedByBranch[$node->getStartLine()];
147149
$returnEndLine = $node->getEndLine();
148150
$nextBranch = null;
149151

152+
if ($node instanceof Node\Stmt\Label) {
153+
$returnEndLine = $node->getStartLine() - 1;
154+
}
155+
150156
foreach ($this->executableLinesGroupedByBranch as $line => $branch) {
151157
if ($line <= $returnEndLine || $branch !== $returnBranch) {
152158
continue;

tests/_files/source_for_branched_exec_lines.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,21 @@ public function withBreak() // +5
297297
++$var; // +3
298298
} // -4
299299
}
300+
public function withGoto() // +5
301+
{ // 0
302+
$var = 1; // 0
303+
if (false) { // 0
304+
++$var; // +1
305+
goto // 0
306+
a // 0
307+
; // 0
308+
++$var; // +1
309+
} // -2
310+
++$var; // 0
311+
a // +3
312+
: // 0
313+
++$var; // 0
314+
b: // +1
315+
++$var; // 0
316+
}
300317
}

0 commit comments

Comments
 (0)