Skip to content

Commit 54cb47b

Browse files
committed
notes
1 parent 2b641d4 commit 54cb47b

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/PhpParser/NodeTraverser/RectorNodeTraverser.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@
1919
use 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
2330
*/
2431
final class RectorNodeTraverser implements NodeTraverserInterface
2532
{
2633
/**
27-
* @var list<NodeVisitor>
34+
* @var RectorInterface[]
2835
*/
2936
private array $visitors = [];
3037

@@ -33,7 +40,7 @@ final class RectorNodeTraverser implements NodeTraverserInterface
3340
private bool $areNodeVisitorsPrepared = false;
3441

3542
/**
36-
* @var array<class-string<Node>, NodeVisitor[]>
43+
* @var array<class-string<Node>, RectorInterface[]>
3744
*/
3845
private array $visitorsPerNodeClass = [];
3946

@@ -103,7 +110,9 @@ public function refreshPhpRectors(array $rectors): void
103110
}
104111

105112
/**
106-
* @return NodeVisitor[]
113+
* @return RectorInterface[]
114+
*
115+
* @api used in tests
107116
*/
108117
public function getVisitorsForNode(Node $node): array
109118
{

0 commit comments

Comments
 (0)