From 78581c79f5f5b69e7eaa31fa354a9815a11272fb Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 19 Feb 2025 11:00:30 +0000 Subject: [PATCH] Updated Rector to commit 0d86656f904c940d8573f4966e753ffb76e010c2 https://github.com/rectorphp/rector-src/commit/0d86656f904c940d8573f4966e753ffb76e010c2 [Performance] Avoid multiple traverse on BetterNodeFinder::hasInstanceof() (#6742) --- src/Application/VersionResolver.php | 4 ++-- src/NodeManipulator/IfManipulator.php | 7 +------ src/PhpParser/Node/BetterNodeFinder.php | 14 +++++++------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 36ef08ccae1..28dd4c658bc 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '5b054eaa33bcd3cede29c544603cd31dd2959631'; + public const PACKAGE_VERSION = '0d86656f904c940d8573f4966e753ffb76e010c2'; /** * @api * @var string */ - public const RELEASE_DATE = '2025-02-19 11:12:02'; + public const RELEASE_DATE = '2025-02-19 17:57:56'; /** * @var int */ diff --git a/src/NodeManipulator/IfManipulator.php b/src/NodeManipulator/IfManipulator.php index 4e8eee08bc4..e6bf571f7cc 100644 --- a/src/NodeManipulator/IfManipulator.php +++ b/src/NodeManipulator/IfManipulator.php @@ -135,12 +135,7 @@ final class IfManipulator if (!$this->isIfWithoutElseAndElseIfs($currentIf)) { return []; } - $return = $this->betterNodeFinder->findFirstInstanceOf($currentIf->stmts, Return_::class); - if ($return instanceof Return_) { - return []; - } - $exit = $this->betterNodeFinder->findFirstInstanceOf($currentIf->stmts, Exit_::class); - if ($exit instanceof Exit_) { + if ($this->betterNodeFinder->hasInstancesOf($currentIf->stmts, [Return_::class, Exit_::class])) { return []; } // last if is with the expression diff --git a/src/PhpParser/Node/BetterNodeFinder.php b/src/PhpParser/Node/BetterNodeFinder.php index abe0e3bb569..83a87c5f8fa 100644 --- a/src/PhpParser/Node/BetterNodeFinder.php +++ b/src/PhpParser/Node/BetterNodeFinder.php @@ -117,14 +117,14 @@ final class BetterNodeFinder public function hasInstancesOf($nodes, array $types) : bool { Assert::allIsAOf($types, Node::class); - foreach ($types as $type) { - $foundNode = $this->nodeFinder->findFirstInstanceOf($nodes, $type); - if (!$foundNode instanceof Node) { - continue; + return (bool) $this->nodeFinder->findFirst($nodes, static function (Node $node) use($types) : bool { + foreach ($types as $type) { + if ($node instanceof $type) { + return \true; + } } - return \true; - } - return \false; + return \false; + }); } /** * @param Node|Node[] $nodes