From 184ece2c94271081d5437cd31905d81d76f5916a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 19 Oct 2026 13:16:50 +0200 Subject: [PATCH] Convert nested closures to arrow functions in a single pass When a closure's arrow body is itself a convertible closure, refactor it in the same call so each closure node is handled once, instead of leaving inner closures for later traverse passes. --- .../Rector/Closure/ClosureToArrowFunctionRector.php | 9 +++++++++ 1 file changed, 9 insertions(+) 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]);