diff --git a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php index 4ae80808728..eb629aeeab8 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php +++ b/src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php @@ -155,8 +155,6 @@ public function processNodes( Assert::allIsInstanceOf($stmts, Stmt::class); - $this->nodeTraverser->traverse($stmts); - $scope = $formerMutatingScope ?? $this->scopeFactory->createFromFile($filePath); $nodeCallback = function (Node $node, MutatingScope $mutatingScope) use ( @@ -419,6 +417,10 @@ public function processNodes( RectorNodeScopeResolver::processNodes($stmts, $scope); } + // use after scope filling so DecoratingNodeVisitorInterface instance can fetch the scope of target node + // @see https://github.com/rectorphp/rector-src/pull/7721#discussion_r2595932460 + $this->nodeTraverser->traverse($stmts); + return $stmts; }