1919use Webmozart \Assert \Assert ;
2020
2121/**
22+ * Based on native NodeTraverser class, but heavily customized for Rector needs.
23+ *
24+ * The main differences are:
25+ * - no leaveNode(), as we do all in enterNode() that calls refactor() method
26+ * - cached visitors per node class for performance, e.g. when we find rules for Class_ node, they're cached for next time
27+ * - immutability features, register Rector rules once, then use; no changes on the fly
28+ *
2229 * @see \Rector\Tests\PhpParser\NodeTraverser\RectorNodeTraverserTest
30+ * @internal No BC promise on this class, it might change any time.
2331 */
2432final class RectorNodeTraverser implements NodeTraverserInterface
2533{
2634 /**
27- * @var list<NodeVisitor>
35+ * @var RectorInterface[]
2836 */
2937 private array $ visitors = [];
3038
@@ -33,17 +41,17 @@ final class RectorNodeTraverser implements NodeTraverserInterface
3341 private bool $ areNodeVisitorsPrepared = false ;
3442
3543 /**
36- * @var array<class-string<Node>, NodeVisitor []>
44+ * @var array<class-string<Node>, RectorInterface []>
3745 */
3846 private array $ visitorsPerNodeClass = [];
3947
4048 /**
4149 * @param RectorInterface[] $rectors
4250 */
4351 public function __construct (
52+ private array $ rectors ,
4453 private readonly PhpVersionedFilter $ phpVersionedFilter ,
4554 private readonly ConfigurationRuleFilter $ configurationRuleFilter ,
46- private array $ rectors
4755 ) {
4856 }
4957
@@ -103,7 +111,9 @@ public function refreshPhpRectors(array $rectors): void
103111 }
104112
105113 /**
106- * @return NodeVisitor[]
114+ * @return RectorInterface[]
115+ *
116+ * @api used in tests
107117 */
108118 public function getVisitorsForNode (Node $ node ): array
109119 {
0 commit comments