Skip to content

Commit 2b94c94

Browse files
authored
[perf] Speed up array_map/array_reduce closure param rules with cheap Closure arg bail before reflection (#8657)
1 parent 2e19201 commit 2b94c94

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayMapRector.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ public function refactor(Node $node): ?Node
7272
return null;
7373
}
7474

75-
$funcReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node);
75+
$args = $node->getArgs();
7676

77-
if (! $funcReflection instanceof NativeFunctionReflection) {
77+
if (! isset($args[0]) || ! $args[0]->value instanceof Closure) {
7878
return null;
7979
}
8080

81-
$args = $node->getArgs();
81+
$funcReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node);
8282

83-
if (! isset($args[0]) || ! $args[0]->value instanceof Closure) {
83+
if (! $funcReflection instanceof NativeFunctionReflection) {
8484
return null;
8585
}
8686

‎rules/TypeDeclaration/Rector/FunctionLike/AddClosureParamTypeForArrayReduceRector.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ public function refactor(Node $node): ?Node
7676
return null;
7777
}
7878

79-
$funcReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node);
79+
$args = $node->getArgs();
8080

81-
if (! $funcReflection instanceof NativeFunctionReflection) {
81+
if (! isset($args[1]) || ! $args[1]->value instanceof Closure) {
8282
return null;
8383
}
8484

85-
$args = $node->getArgs();
85+
$funcReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node);
8686

87-
if (! isset($args[1]) || ! $args[1]->value instanceof Closure) {
87+
if (! $funcReflection instanceof NativeFunctionReflection) {
8888
return null;
8989
}
9090

0 commit comments

Comments
 (0)