@@ -36,13 +36,10 @@ final class RectorNodeTraverser implements NodeTraverserInterface
3636 private array $ visitorsPerNodeClass = [];
3737
3838 /**
39- * @var list<NodeVisitor> Visitors
39+ * @var RectorInterface[]
4040 */
4141 private array $ visitors = [];
4242
43- /**
44- * @var bool Whether traversal should be stopped
45- */
4643 private bool $ stopTraversal ;
4744
4845 /**
@@ -55,17 +52,6 @@ public function __construct(
5552 ) {
5653 }
5754
58- // /**
59- // * @param Stmt[] $rectors
60- // * @return Stmt[]
61- // */
62- // public function traverse(array $nodes): array
63- // {
64- // $this->prepareNodeVisitors();
65- //
66- // return parent::traverse($nodes);
67- // }
68-
6955 /**
7056 * @param RectorInterface[] $rectors
7157 * @api used in tests to update the active rules
@@ -117,18 +103,6 @@ public function getVisitorsForNode(Node $node): array
117103 }
118104
119105 /**
120- // * Create a traverser with the given visitors.
121- // *
122- // * @param NodeVisitor ...$visitor Node visitors
123- // */
124- // public function __construct(NodeVisitor ...$visitors)
125- // {
126- // $this->visitors = $visitors;
127- // }
128-
129- /**
130- * Adds a visitor.
131- *
132106 * @deprecated @todo remove completely, even in tests to avoid mutable state
133107 */
134108 public function addVisitor (NodeVisitor $ visitor ): void
@@ -142,11 +116,8 @@ public function removeVisitor(NodeVisitor $visitor): void
142116 }
143117
144118 /**
145- * Traverses an array of nodes using the registered visitors.
146- *
147- * @param Node[] $nodes Array of nodes
148- *
149- * @return Node[] Traversed array of nodes
119+ * @param Node[] $nodes
120+ * @return Node[]
150121 */
151122 public function traverse (array $ nodes ): array
152123 {
@@ -171,7 +142,8 @@ public function traverse(array $nodes): array
171142 }
172143
173144 /**
174- * This must happen after $this->configuration is set after ProcessCommand::execute() is run, otherwise we get default false positives.
145+ * This must happen after $this->configuration is set after ProcessCommand::execute() is run,
146+ * otherwise we get default false positives.
175147 *
176148 * This should be removed after https://github.com/rectorphp/rector/issues/5584 is resolved
177149 */
@@ -181,10 +153,7 @@ private function prepareNodeVisitors(): void
181153 return ;
182154 }
183155
184- // filer out by version
185156 $ this ->visitors = $ this ->phpVersionedFilter ->filter ($ this ->rectors );
186-
187- // filter by configuration
188157 $ this ->visitors = $ this ->configurationRuleFilter ->filter ($ this ->visitors );
189158
190159 $ this ->areNodeVisitorsPrepared = true ;
@@ -233,9 +202,6 @@ private function traverseNode(Node $node): void
233202 } elseif ($ return === NodeVisitor::STOP_TRAVERSAL ) {
234203 $ this ->stopTraversal = true ;
235204 break 2 ;
236- } elseif ($ return === NodeVisitor::REPLACE_WITH_NULL ) {
237- $ node ->{$ name } = null ;
238- continue 2 ;
239205 } else {
240206 throw new LogicException ('enterNode() returned invalid value of type ' . gettype ($ return ));
241207 }
@@ -253,21 +219,25 @@ private function traverseNode(Node $node): void
253219
254220 /**
255221 * @param Node[] $nodes
256- * @return \PhpParser\ Node[] Result of traversal (may be original array or changed one)
222+ * @return Node[]
257223 */
258224 private function traverseArray (array $ nodes ): array
259225 {
260226 $ doNodes = [];
261227 foreach ($ nodes as $ i => $ node ) {
262228 if (! $ node instanceof Node) {
263229 if (\is_array ($ node )) {
264- throw new LogicException ('Invalid node structure: Contains nested arrays ' );
230+ throw new LogicException (sprintf (
231+ 'Invalid node "%s" structure: Contains nested arrays ' ,
232+ $ node ::class,
233+ ));
265234 }
266235
267236 continue ;
268237 }
269238
270239 $ traverseChildren = true ;
240+
271241 $ currentNodeVisitors = $ this ->getVisitorsForNode ($ node );
272242
273243 foreach ($ currentNodeVisitors as $ currentNodeVisitor ) {
@@ -296,10 +266,6 @@ private function traverseArray(array $nodes): array
296266 } elseif ($ return === NodeVisitor::STOP_TRAVERSAL ) {
297267 $ this ->stopTraversal = true ;
298268 break 2 ;
299- } elseif ($ return === NodeVisitor::REPLACE_WITH_NULL ) {
300- throw new LogicException (
301- 'REPLACE_WITH_NULL can not be used if the parent structure is an array '
302- );
303269 } else {
304270 throw new LogicException ('enterNode() returned invalid value of type ' . gettype ($ return ));
305271 }
0 commit comments