From 8e358ac3b732987cb1edecf8923c7a457e44b125 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 28 Aug 2023 12:28:59 +0700 Subject: [PATCH] [Performance] No need to traverseNodesWithCallable() when only single node types on decorateCurrentAndChildren --- src/Rector/AbstractRector.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index e5e5c0ecc6e..88a96adf812 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -226,12 +226,17 @@ private function decorateCurrentAndChildren(Node $node): void // 1. registered in getNodesTypes() method // 2. different with current node type, as already decorated above // - $types = array_filter( + $otherTypes = array_filter( $this->getNodeTypes(), static fn (string $nodeType): bool => $nodeType !== $node::class ); - $this->traverseNodesWithCallable($node, static function (Node $subNode) use ($types) { - if (in_array($subNode::class, $types, true)) { + + if ($otherTypes === []) { + return; + } + + $this->traverseNodesWithCallable($node, static function (Node $subNode) use ($otherTypes) { + if (in_array($subNode::class, $otherTypes, true)) { $subNode->setAttribute(AttributeKey::SKIPPED_BY_RECTOR_RULE, static::class); $subNode->setAttribute(AttributeKey::SKIPPED_BY_RECTOR_RULE, static::class); }