Skip to content

Commit

Permalink
[NodeTraverser] Traverse fill stmt_key after FileWithoutNamespaceNode…
Browse files Browse the repository at this point in the history
…Traverser on PHPStanNodeScopeResolver (#4103)
  • Loading branch information
samsonasik committed Jun 7, 2023
1 parent aa0c9af commit a43321f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,24 @@ public function processNodes(
*/

Assert::allIsInstanceOf($stmts, Stmt::class);
$this->nodeTraverser->traverse($stmts);

$isInitFileWithoutNamespace = false;
if (! $isScopeRefreshing && ! current($stmts) instanceof FileWithoutNamespace) {
$stmts = $this->fileWithoutNamespaceNodeTraverser->traverse($stmts);

$currentStmt = current($stmts);
if ($currentStmt instanceof FileWithoutNamespace) {
$this->nodeTraverser->traverse($stmts);
$stmts = $currentStmt->stmts;

$isInitFileWithoutNamespace = true;
}
}

if (! $isInitFileWithoutNamespace) {
$this->nodeTraverser->traverse($stmts);
}

$scope = $formerMutatingScope ?? $this->scopeFactory->createFromFile($filePath);

// skip chain method calls, performance issue: https://github.com/phpstan/phpstan/issues/254
Expand Down
4 changes: 0 additions & 4 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ public function beforeTraverse(array $nodes): ?array
$childStmt->setAttribute(AttributeKey::STMT_KEY, $key);
continue;
}

foreach ($childStmt->stmts as $keyChildStmt => $childStmtStmt) {
$childStmtStmt->setAttribute(AttributeKey::STMT_KEY, $keyChildStmt);
}
}

return parent::beforeTraverse($nodes);
Expand Down

0 comments on commit a43321f

Please sign in to comment.