1111use PhpParser \NodeVisitor ;
1212use Rector \Application \RectorRegistry ;
1313use Rector \Rector \RectorRunner ;
14+ use Rector \ValueObject \Application \File ;
1415
1516final class RectorNodeTraverser
1617{
@@ -26,19 +27,19 @@ public function __construct(
2627 * @param Node[] $nodes
2728 * @return Node[]
2829 */
29- public function traverse (array $ nodes ): array
30+ public function traverse (array $ nodes, File $ file ): array
3031 {
3132 $ this ->stopTraversal = false ;
3233
33- return $ this ->traverseArray ($ nodes );
34+ return $ this ->traverseArray ($ nodes, $ file );
3435 }
3536
36- private function traverseNode (Node $ node ): void
37+ private function traverseNode (Node $ node, File $ file ): void
3738 {
3839 foreach ($ node ->getSubNodeNames () as $ name ) {
3940 $ subNode = $ node ->{$ name };
4041 if (\is_array ($ subNode )) {
41- $ node ->{$ name } = $ this ->traverseArray ($ subNode );
42+ $ node ->{$ name } = $ this ->traverseArray ($ subNode, $ file );
4243 if ($ this ->stopTraversal ) {
4344 break ;
4445 }
@@ -50,7 +51,7 @@ private function traverseNode(Node $node): void
5051 continue ;
5152 }
5253
53- $ currentNodeVisitors = $ this ->rectorRegistry ->forNode ($ subNode );
54+ $ currentNodeVisitors = $ this ->rectorRegistry ->forNodeAndFile ($ subNode, $ file );
5455
5556 foreach ($ currentNodeVisitors as $ currentNodeVisitor ) {
5657 $ return = $ this ->rectorRunner ->run ($ currentNodeVisitor , $ subNode );
@@ -74,7 +75,8 @@ private function traverseNode(Node $node): void
7475 }
7576 }
7677
77- $ this ->traverseNode ($ subNode );
78+ $ this ->traverseNode ($ subNode , $ file );
79+
7880 if ($ this ->stopTraversal ) {
7981 break ;
8082 }
@@ -85,7 +87,7 @@ private function traverseNode(Node $node): void
8587 * @param array<Node|null> $nodes The null can be in case of empty list(, , )
8688 * @return Node[]
8789 */
88- private function traverseArray (array $ nodes ): array
90+ private function traverseArray (array $ nodes, File $ file ): array
8991 {
9092 $ doNodes = [];
9193 foreach ($ nodes as $ i => $ node ) {
@@ -97,7 +99,7 @@ private function traverseArray(array $nodes): array
9799 continue ;
98100 }
99101
100- $ currentNodeVisitors = $ this ->rectorRegistry ->forNode ($ node );
102+ $ currentNodeVisitors = $ this ->rectorRegistry ->forNodeAndFile ($ node, $ file );
101103
102104 foreach ($ currentNodeVisitors as $ currentNodeVisitor ) {
103105 $ return = $ this ->rectorRunner ->run ($ currentNodeVisitor , $ node );
@@ -123,7 +125,7 @@ private function traverseArray(array $nodes): array
123125 }
124126 }
125127
126- $ this ->traverseNode ($ node );
128+ $ this ->traverseNode ($ node, $ file );
127129 if ($ this ->stopTraversal ) {
128130 break ;
129131 }
0 commit comments