Skip to content

Commit bc8c899

Browse files
committed
final touch: allow register inner function as next of after unreachable statement
1 parent 78e6d1a commit bc8c899

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
@@ -6226,7 +6226,12 @@ private function getPhpDocReturnType(ResolvedPhpDocBlock $resolvedPhpDoc, Type $
62266226
private function getNextUnreachableStatements(array $nodes, bool $earlyBinding): array
62276227
{
62286228
$stmts = [];
6229+
$isPassedUnreachableStatement = false;
62296230
foreach ($nodes as $node) {
6231+
if ($isPassedUnreachableStatement) {
6232+
$stmts[] = $node;
6233+
continue;
6234+
}
62306235
if ($node instanceof Node\Stmt\Nop) {
62316236
continue;
62326237
}
@@ -6237,6 +6242,7 @@ private function getNextUnreachableStatements(array $nodes, bool $earlyBinding):
62376242
continue;
62386243
}
62396244
$stmts[] = $node;
6245+
$isPassedUnreachableStatement = true;
62406246
}
62416247
return $stmts;
62426248
}

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)