Skip to content

Commit

Permalink
final touch: allow register inner function as next of after unreachab…
Browse files Browse the repository at this point in the history
…le statement
  • Loading branch information
samsonasik committed Dec 22, 2024
1 parent 78e6d1a commit bc8c899
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6226,7 +6226,12 @@ private function getPhpDocReturnType(ResolvedPhpDocBlock $resolvedPhpDoc, Type $
private function getNextUnreachableStatements(array $nodes, bool $earlyBinding): array
{
$stmts = [];
$isPassedUnreachableStatement = false;
foreach ($nodes as $node) {
if ($isPassedUnreachableStatement) {
$stmts[] = $node;
continue;
}
if ($node instanceof Node\Stmt\Nop) {
continue;
}
Expand All @@ -6237,6 +6242,7 @@ private function getNextUnreachableStatements(array $nodes, bool $earlyBinding):
continue;
}
$stmts[] = $node;
$isPassedUnreachableStatement = true;
}
return $stmts;

Check failure on line 6247 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Method PHPStan\Analyser\NodeScopeResolver::getNextUnreachableStatements() should return list<PhpParser\Node\Stmt> but returns list<T of PhpParser\Node>.

Check failure on line 6247 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Method PHPStan\Analyser\NodeScopeResolver::getNextUnreachableStatements() should return list<PhpParser\Node\Stmt> but returns list<T of PhpParser\Node>.

Check failure on line 6247 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Method PHPStan\Analyser\NodeScopeResolver::getNextUnreachableStatements() should return list<PhpParser\Node\Stmt> but returns list<T of PhpParser\Node>.

Check failure on line 6247 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Method PHPStan\Analyser\NodeScopeResolver::getNextUnreachableStatements() should return list<PhpParser\Node\Stmt> but returns list<T of PhpParser\Node>.

Check failure on line 6247 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Method PHPStan\Analyser\NodeScopeResolver::getNextUnreachableStatements() should return list<PhpParser\Node\Stmt> but returns list<T of PhpParser\Node>.

Check failure on line 6247 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Method PHPStan\Analyser\NodeScopeResolver::getNextUnreachableStatements() should return list<PhpParser\Node\Stmt> but returns list<T of PhpParser\Node>.

Check failure on line 6247 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Method PHPStan\Analyser\NodeScopeResolver::getNextUnreachableStatements() should return list<PhpParser\Node\Stmt> but returns list<T of PhpParser\Node>.

Check failure on line 6247 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Method PHPStan\Analyser\NodeScopeResolver::getNextUnreachableStatements() should return list<PhpParser\Node\Stmt> but returns list<T of PhpParser\Node>.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function processNode(Node $node, Scope $scope): array
$totalNextStatements = count($node->getNextStatements());

return [
RuleErrorBuilder::message(sprintf('It has %d over first unreachable statements', $totalNextStatements))
RuleErrorBuilder::message(sprintf('It has %d stmts over first unreachable statements', $totalNextStatements))
->identifier('tests.total.next.unreachable.statement')
->build(),
];
Expand All @@ -50,7 +50,7 @@ public function testRule(): void
{
$this->analyse([__DIR__ . '/data/multiple_unreachable.php'], [
[
'It has 2 over first unreachable statements',
'It has 3 stmts over first unreachable statements',
14,
],
]);
Expand Down
8 changes: 7 additions & 1 deletion tests/PHPStan/Rules/DeadCode/data/multiple_unreachable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ function foo($foo)

echo 'statement 1';
echo 'statement 2';
echo 'statement 3';

function innerFunction()
{
echo 'statement 3';
}

echo innerFunction();
}

0 comments on commit bc8c899

Please sign in to comment.