File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77use PhpParser \Node ;
88use PhpParser \Node \Stmt ;
99use PhpParser \Node \Stmt \Namespace_ ;
10+ use PhpParser \NodeVisitor ;
1011use Rector \CodingStyle \Application \UseImportsRemover ;
1112use Rector \Configuration \Option ;
1213use Rector \Configuration \Parameter \SimpleParameterProvider ;
@@ -47,17 +48,21 @@ public function beforeTraverse(array $nodes): array
4748 }
4849 }
4950
51+ $ this ->renamedNameCollector ->reset ();
5052 return $ nodes ;
5153 }
5254
53- /**
54- * @param Node[] $nodes
55- * @return Stmt[]
56- */
57- public function afterTraverse (array $ nodes ): array
55+ public function enterNode (Node $ node ): int
5856 {
59- $ this ->renamedNameCollector ->reset ();
60- return $ nodes ;
57+ /**
58+ * We stop the traversal because all the work has already been done in the beforeTraverse() function
59+ *
60+ * Using STOP_TRAVERSAL is usually dangerous as it will stop the processing of all your nodes for all visitors
61+ * but since the PostFileProcessor is using direct new NodeTraverser() and traverse() for only a single
62+ * visitor per execution, using stop traversal here is safe,
63+ * ref https://github.com/rectorphp/rector-src/blob/fc1e742fa4d9861ccdc5933f3b53613b8223438d/src/PostRector/Application/PostFileProcessor.php#L59-L61
64+ */
65+ return NodeVisitor::STOP_TRAVERSAL ;
6166 }
6267
6368 public function shouldTraverse (array $ stmts ): bool
You can’t perform that action at this time.
0 commit comments