Skip to content

Commit afd35aa

Browse files
committed
final touch: allow register inner function as next of after unreachable statement
1 parent 8ad84c0 commit afd35aa

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6543,7 +6543,12 @@ private function getPhpDocReturnType(ResolvedPhpDocBlock $resolvedPhpDoc, Type $
65436543
private function getNextUnreachableStatements(array $nodes, bool $earlyBinding): array
65446544
{
65456545
$stmts = [];
6546+
$isPassedUnreachableStatement = false;
65466547
foreach ($nodes as $node) {
6548+
if ($isPassedUnreachableStatement) {
6549+
$stmts[] = $node;
6550+
continue;
6551+
}
65476552
if ($node instanceof Node\Stmt\Nop) {
65486553
continue;
65496554
}
@@ -6554,6 +6559,7 @@ private function getNextUnreachableStatements(array $nodes, bool $earlyBinding):
65546559
continue;
65556560
}
65566561
$stmts[] = $node;
6562+
$isPassedUnreachableStatement = true;
65576563
}
65586564
return $stmts;
65596565
}

tests/PHPStan/Rules/DeadCode/UnreachableStatementNextStatementsRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
3737
$totalNextStatements = count($node->getNextStatements());
3838

3939
return [
40-
RuleErrorBuilder::message(sprintf('It has %d over first unreachable statements', $totalNextStatements))
40+
RuleErrorBuilder::message(sprintf('It has %d stmts over first unreachable statements', $totalNextStatements))
4141
->identifier('tests.total.next.unreachable.statement')
4242
->build(),
4343
];
@@ -50,7 +50,7 @@ public function testRule(): void
5050
{
5151
$this->analyse([__DIR__ . '/data/multiple_unreachable.php'], [
5252
[
53-
'It has 2 over first unreachable statements',
53+
'It has 3 stmts over first unreachable statements',
5454
14,
5555
],
5656
]);

tests/PHPStan/Rules/DeadCode/data/multiple_unreachable.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@ function foo($foo)
1313

1414
echo 'statement 1';
1515
echo 'statement 2';
16-
echo 'statement 3';
16+
17+
function innerFunction()
18+
{
19+
echo 'statement 3';
20+
}
21+
22+
echo innerFunction();
1723
}

0 commit comments

Comments
 (0)