diff --git a/rules/Php74/Rector/Closure/ClosureToArrowFunctionRector.php b/rules/Php74/Rector/Closure/ClosureToArrowFunctionRector.php index 6a71b1528ca..ffbc602a20b 100644 --- a/rules/Php74/Rector/Closure/ClosureToArrowFunctionRector.php +++ b/rules/Php74/Rector/Closure/ClosureToArrowFunctionRector.php @@ -77,6 +77,15 @@ public function refactor(Node $node): ?Node return null; } + // convert a directly nested closure in the same pass, so each closure node is handled once + // instead of leaving the inner one for another traverse pass + if ($returnExpr instanceof Closure) { + $nestedArrowFunction = $this->refactor($returnExpr); + if ($nestedArrowFunction instanceof Expr) { + $returnExpr = $nestedArrowFunction; + } + } + $attributes = $node->getAttributes(); unset($attributes[AttributeKey::ORIGINAL_NODE]);