From 79a630987e9afffb7edda0380099472b04f2e211 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 21 Apr 2023 11:06:08 +0700 Subject: [PATCH] [Performance] Using findFirst() for cast to (bool) so no need search all found nodes (#3642) * [Performance] Using findFirst() for cast to (bool) so no need search all found node * rollback negation * findFirst should be ok for negation, since it can return true on found --- .../FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php | 2 +- src/NodeManipulator/ClassConstManipulator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/CodeQuality/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php b/rules/CodeQuality/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php index 8ccd82f8078..4caa23aa576 100644 --- a/rules/CodeQuality/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php +++ b/rules/CodeQuality/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php @@ -131,7 +131,7 @@ private function findPreviousAssignToArrayKeys(FuncCall $funcCall, Expr $expr): } if (! $node instanceof Assign) { - return ! (bool) $this->betterNodeFinder->find( + return ! (bool) $this->betterNodeFinder->findFirst( $node, fn (Node $subNode): bool => $this->nodeComparator->areNodesEqual($expr, $subNode) ); diff --git a/src/NodeManipulator/ClassConstManipulator.php b/src/NodeManipulator/ClassConstManipulator.php index 373b79e899f..c6a993afe82 100644 --- a/src/NodeManipulator/ClassConstManipulator.php +++ b/src/NodeManipulator/ClassConstManipulator.php @@ -40,7 +40,7 @@ public function hasClassConstFetch(ClassConst $classConst, ClassReflection $clas } // has in class? - $isClassConstFetchFound = (bool) $this->betterNodeFinder->find($ancestorClass, function (Node $node) use ( + $isClassConstFetchFound = (bool) $this->betterNodeFinder->findFirst($ancestorClass, function (Node $node) use ( $classConst, $className ): bool {