Skip to content

Commit

Permalink
[NodeTypeResolver] Remove next node on PHPStanNodeScopeResolver (#3888)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed May 18, 2023
1 parent 1c2865a commit 24f8610
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use PHPStan\Type\TypeCombinator;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Caching\FileSystem\DependencyResolver;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
Expand Down Expand Up @@ -325,12 +326,22 @@ private function processUnreachableStatementNode(

$this->processNodes([$originalStmt], $filePath, $mutatingScope);

$nextNode = $originalStmt->getAttribute(AttributeKey::NEXT_NODE);
while ($nextNode instanceof Stmt) {
$nextNode->setAttribute(AttributeKey::IS_UNREACHABLE, true);
$parentNode = $unreachableStatementNode->getAttribute(AttributeKey::PARENT_NODE);

$this->processNodes([$nextNode], $filePath, $mutatingScope);
$nextNode = $nextNode->getAttribute(AttributeKey::NEXT_NODE);
if (! $parentNode instanceof StmtsAwareInterface) {
return;
}

$stmtKey = $unreachableStatementNode->getAttribute(AttributeKey::STMT_KEY);
$totalKeys = $parentNode->stmts === null ? 0 : count($parentNode->stmts);

for ($key = $stmtKey + 1; $key < $totalKeys; ++$key) {
if (! isset($parentNode->stmts[$key])) {
continue;
}

$parentNode->stmts[$key]->setAttribute(AttributeKey::IS_UNREACHABLE, true);
$this->processNodes([$parentNode->stmts[$key]], $filePath, $mutatingScope);
}
}

Expand Down

0 comments on commit 24f8610

Please sign in to comment.