From b78fd5ccbb9f33e77f6c3b211dcbd8bf16644a9a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 14 Oct 2026 23:53:31 +0200 Subject: [PATCH] [TypeDeclaration] Speed up array_map/array_reduce closure param rules with cheap Closure arg bail before reflection --- .../FunctionLike/AddClosureParamTypeForArrayMapRector.php | 8 ++++---- .../AddClosureParamTypeForArrayReduceRector.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php b/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php index f5f823e8ff2..5d09f00f313 100644 --- a/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php +++ b/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php @@ -72,15 +72,15 @@ public function refactor(Node $node): ?Node return null; } - $funcReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node); + $args = $node->getArgs(); - if (! $funcReflection instanceof NativeFunctionReflection) { + if (! isset($args[0]) || ! $args[0]->value instanceof Closure) { return null; } - $args = $node->getArgs(); + $funcReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node); - if (! isset($args[0]) || ! $args[0]->value instanceof Closure) { + if (! $funcReflection instanceof NativeFunctionReflection) { return null; } diff --git a/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php b/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php index 24971671843..19c0129afe0 100644 --- a/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php +++ b/rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php @@ -76,15 +76,15 @@ public function refactor(Node $node): ?Node return null; } - $funcReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node); + $args = $node->getArgs(); - if (! $funcReflection instanceof NativeFunctionReflection) { + if (! isset($args[1]) || ! $args[1]->value instanceof Closure) { return null; } - $args = $node->getArgs(); + $funcReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node); - if (! isset($args[1]) || ! $args[1]->value instanceof Closure) { + if (! $funcReflection instanceof NativeFunctionReflection) { return null; }