diff --git a/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/skip_anonymous_class.php.inc b/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/skip_anonymous_class.php.inc index 76bab72d64a..0f0d7040f1e 100644 --- a/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/skip_anonymous_class.php.inc +++ b/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/skip_anonymous_class.php.inc @@ -18,8 +18,7 @@ class SkipAnonymousClass $nodes = $nodes ? [$nodes] : []; } - $nodeTraverser = new NodeTraverser(); - $nodeTraverser->addVisitor($this->createNodeVisitor($callable)); + $nodeTraverser = new NodeTraverser(...$this->createNodeVisitor($callable)); $nodeTraverser->traverse($nodes); } diff --git a/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php b/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php index 0aeea1d7918..cb35b3afa3f 100644 --- a/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php +++ b/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php @@ -14,64 +14,25 @@ abstract class AbstractImmutableNodeTraverser implements NodeTraverserInterface { /** - * @deprecated Use NodeVisitor::DONT_TRAVERSE_CHILDREN instead. - */ - public const DONT_TRAVERSE_CHILDREN = NodeVisitor::DONT_TRAVERSE_CHILDREN; - - /** - * @deprecated Use NodeVisitor::STOP_TRAVERSAL instead. - */ - public const STOP_TRAVERSAL = NodeVisitor::STOP_TRAVERSAL; - - /** - * @deprecated Use NodeVisitor::REMOVE_NODE instead. - */ - public const REMOVE_NODE = NodeVisitor::REMOVE_NODE; - - /** - * @deprecated Use NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN instead. - */ - public const DONT_TRAVERSE_CURRENT_AND_CHILDREN = NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; - - /** - * @var list Visitors + * @var list */ protected array $visitors = []; - /** - * @var bool Whether traversal should be stopped - */ - protected bool $stopTraversal; + private bool $stopTraversal; - /** - * Create a traverser with the given visitors. - * - * @param NodeVisitor ...$visitors Node visitors - */ public function __construct(NodeVisitor ...$visitors) { $this->visitors = $visitors; } - /** - * Adds a visitor. - * - * @param NodeVisitor $visitor Visitor to add - */ public function addVisitor(NodeVisitor $visitor): void { $this->visitors[] = $visitor; } - /** - * Removes an added visitor. - */ public function removeVisitor(NodeVisitor $visitor): void { - $index = array_search($visitor, $this->visitors, true); - if ($index !== false) { - array_splice($this->visitors, $index, 1, []); - } + throw new LogicException('Removing visitors is not supported in ' . static::class); } /** @@ -106,12 +67,7 @@ public function traverse(array $nodes): array */ abstract public function getVisitorsForNode(Node $node): array; - /** - * Recursively traverse a node. - * - * @param Node $node Node to traverse. - */ - protected function traverseNode(Node $node): void + private function traverseNode(Node $node): void { foreach ($node->getSubNodeNames() as $name) { $subNode = $node->{$name}; @@ -193,9 +149,9 @@ protected function traverseNode(Node $node): void * * @param Node[] $nodes Array to traverse * - * @return array Result of traversal (may be original array or changed one) + * @return Node[] Result of traversal (may be original array or changed one) */ - protected function traverseArray(array $nodes): array + private function traverseArray(array $nodes): array { $doNodes = []; foreach ($nodes as $i => $node) {