Skip to content

Commit

Permalink
match arms depent too much on autoloading runtime behavior, process…
Browse files Browse the repository at this point in the history
… it as a whole
  • Loading branch information
Slamdunk authored and sebastianbergmann committed Dec 14, 2022
1 parent 4ad55a2 commit ede00c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
13 changes: 1 addition & 12 deletions src/StaticAnalysis/ExecutableLinesFindingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function enterNode(Node $node): void
$node instanceof Node\Stmt\TryCatch ||
$node instanceof Node\Stmt\Use_ ||
$node instanceof Node\Stmt\UseUse ||
$node instanceof Node\Expr\Match_ ||
$node instanceof Node\Expr\Variable ||
$node instanceof Node\Const_ ||
$node instanceof Node\Identifier ||
Expand Down Expand Up @@ -241,18 +242,6 @@ public function enterNode(Node $node): void
return;
}

if ($node instanceof Node\Expr\Match_) {
foreach ($node->arms as $arm) {
$this->setLineBranch(
$arm->body->getStartLine(),
$arm->body->getEndLine(),
++$this->nextBranch
);
}

return;
}

if ($node instanceof Node\Stmt\Catch_) {
assert([] !== $node->types);
$startLine = $node->types[0]->getStartLine();
Expand Down
26 changes: 13 additions & 13 deletions tests/_files/source_for_branched_exec_lines.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ public function withMatch()
{
$var = 1; // +1
$var2 = match ($var) { // +1
0 => ++$var, // +1
1 => ++$var, // +1
default => ++$var, // +1
}; // -3
$var2 // +4
0 => ++$var, // 0
1 => ++$var, // 0
default => ++$var, // 0
}; // 0
$var2 // +1
= // 0
match // 0
( // 0
Expand All @@ -256,23 +256,23 @@ public function withMatch()
{ // 0
0 // 0
=> // 0
++$var // +1
, // -1
++$var // 0
, // 0
1, // 0
2 // 0
=> // 0
++$var // +2
, // -2
++$var // 0
, // 0
default // 0
=> // 0
++$var // +3
, // -3
++$var // 0
, // 0
} // 0
; // 0
}
public function withReturn()
{
$var = 1; // +4
$var = 1; // +1
if (false) { // +1
++$var; // +1
return // +1
Expand Down Expand Up @@ -568,4 +568,4 @@ final class MyFinalClass extends MyAbstractClass
public function myMethod(): void
{
} // +4
}
}

0 comments on commit ede00c7

Please sign in to comment.