From a3f71d5b3927438a55eb4438bb7eb02f87678f51 Mon Sep 17 00:00:00 2001 From: Carlos Granados Date: Thu, 20 Mar 2025 21:44:51 +0100 Subject: [PATCH] Fix WrapReturnRector --- .../Rector/ClassMethod/WrapReturnRector.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rules/Transform/Rector/ClassMethod/WrapReturnRector.php b/rules/Transform/Rector/ClassMethod/WrapReturnRector.php index 56610b8ddd3..26e5ba610ac 100644 --- a/rules/Transform/Rector/ClassMethod/WrapReturnRector.php +++ b/rules/Transform/Rector/ClassMethod/WrapReturnRector.php @@ -86,8 +86,9 @@ public function refactor(Node $node): ?Node continue; } - $this->wrap($classMethod, $typeMethodWrap->isArrayWrap()); - $hasChanged = true; + if ($typeMethodWrap->isArrayWrap() && $this->wrap($classMethod)) { + $hasChanged = true; + } } } @@ -107,22 +108,21 @@ public function configure(array $configuration): void $this->typeMethodWraps = $configuration; } - private function wrap(ClassMethod $classMethod, bool $isArrayWrap): ?ClassMethod + private function wrap(ClassMethod $classMethod): bool { if (! is_iterable($classMethod->stmts)) { - return null; + return false; } - foreach ($classMethod->stmts as $key => $stmt) { - if ($stmt instanceof Return_ && $stmt->expr instanceof Expr) { - if ($isArrayWrap && ! $stmt->expr instanceof Array_) { - $stmt->expr = new Array_([new ArrayItem($stmt->expr)]); - } - - $classMethod->stmts[$key] = $stmt; + $hasChanged = false; + foreach ($classMethod->stmts as $stmt) { + if ($stmt instanceof Return_ && $stmt->expr instanceof Expr + && ! $stmt->expr instanceof Array_) { + $stmt->expr = new Array_([new ArrayItem($stmt->expr)]); + $hasChanged = true; } } - return $classMethod; + return $hasChanged; } }