diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 70bf5542b8..2ffd8fb233 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -309,6 +309,11 @@ public function processNodes( $alreadyTerminated = true; $nextStmts = $this->getNextUnreachableStatements(array_slice($nodes, $i + 1), true); + + if ($nextStmts === []) { + continue; + } + $unreachableStatementNode = null; foreach ($nextStmts as $nextStmt) { if ($unreachableStatementNode instanceof UnreachableStatementNode) { @@ -317,8 +322,9 @@ public function processNodes( } $unreachableStatementNode = new UnreachableStatementNode($nextStmt); - $nodeCallback($unreachableStatementNode, $scope); } + + $nodeCallback($unreachableStatementNode, $scope); } } @@ -407,6 +413,10 @@ public function processStmtNodes( $alreadyTerminated = true; $nextStmts = $this->getNextUnreachableStatements(array_slice($stmts, $i + 1), $parentNode instanceof Node\Stmt\Namespace_); + if ($nextStmts === []) { + continue; + } + $unreachableStatementNode = null; foreach ($nextStmts as $nextStmt) { if ($unreachableStatementNode instanceof UnreachableStatementNode) { @@ -415,8 +425,9 @@ public function processStmtNodes( } $unreachableStatementNode = new UnreachableStatementNode($nextStmt); - $nodeCallback($unreachableStatementNode, $scope); } + + $nodeCallback($unreachableStatementNode, $scope); } $statementResult = new StatementResult($scope, $hasYield, $alreadyTerminated, $exitPoints, $throwPoints, $impurePoints); @@ -6211,7 +6222,7 @@ private function getPhpDocReturnType(ResolvedPhpDocBlock $resolvedPhpDoc, Type $ /** * @template T of Node * @param array $nodes - * @return Node\Stmt[] + * @return list */ private function getNextUnreachableStatements(array $nodes, bool $earlyBinding): array { @@ -6223,7 +6234,7 @@ private function getNextUnreachableStatements(array $nodes, bool $earlyBinding): if ($earlyBinding && ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassLike || $node instanceof Node\Stmt\HaltCompiler)) { continue; } - if (! $node instanceof Node\Stmt) { + if (!$node instanceof Node\Stmt) { continue; } $stmts[] = $node;