Skip to content

Commit 1e66aba

Browse files
authored
[perf] Hoist cheap node guards before reflection/scope in two rules (#8706)
1 parent 3363fa2 commit 1e66aba

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎rules/CodeQuality/Rector/Attribute/ExplicitAttributeNamedArgsRector.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public function getNodeTypes(): array
6565
*/
6666
public function refactor(Node $node): ?Node
6767
{
68+
// no arguments to name
69+
if ($node->args === []) {
70+
return null;
71+
}
72+
6873
$methodReflection = $this->reflectionResolver->resolveConstructorReflectionFromAttribute($node);
6974
if (! $methodReflection instanceof MethodReflection) {
7075
return null;

‎rules/Php81/Rector/Array_/ArrayToFirstClassCallableRector.php‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,31 +102,31 @@ public function refactor(Node $node): StaticCall|MethodCall|null
102102
return null;
103103
}
104104

105-
$scope = ScopeFetcher::fetch($node);
106-
107-
$arrayCallable = $this->arrayCallableMethodMatcher->match($node, $scope);
108-
if (! $arrayCallable instanceof ArrayCallable) {
105+
if ($node->getAttribute(AttributeKey::IS_CLASS_CONST_VALUE)) {
109106
return null;
110107
}
111108

112-
$callerExpr = $arrayCallable->getCallerExpr();
113-
if (! $callerExpr instanceof Variable && ! $callerExpr instanceof PropertyFetch && ! $callerExpr instanceof ClassConstFetch) {
109+
if ($node->getAttribute(AttributeKey::IS_DEFAULT_PROPERTY_VALUE)) {
114110
return null;
115111
}
116112

117-
if ($node->getAttribute(AttributeKey::IS_CLASS_CONST_VALUE)) {
113+
if ($node->getAttribute(AttributeKey::IS_PARAM_DEFAULT)) {
118114
return null;
119115
}
120116

121-
if ($node->getAttribute(AttributeKey::IS_DEFAULT_PROPERTY_VALUE)) {
117+
if ($node->getAttribute(AttributeKey::IS_UNPACKED_ARG_VALUE)) {
122118
return null;
123119
}
124120

125-
if ($node->getAttribute(AttributeKey::IS_PARAM_DEFAULT)) {
121+
$scope = ScopeFetcher::fetch($node);
122+
123+
$arrayCallable = $this->arrayCallableMethodMatcher->match($node, $scope);
124+
if (! $arrayCallable instanceof ArrayCallable) {
126125
return null;
127126
}
128127

129-
if ($node->getAttribute(AttributeKey::IS_UNPACKED_ARG_VALUE)) {
128+
$callerExpr = $arrayCallable->getCallerExpr();
129+
if (! $callerExpr instanceof Variable && ! $callerExpr instanceof PropertyFetch && ! $callerExpr instanceof ClassConstFetch) {
130130
return null;
131131
}
132132

0 commit comments

Comments
 (0)