Skip to content

Commit 2d8dce0

Browse files
authored
[perf] Resolve method name before receiver type in reflection and AST resolvers (#8682)
1 parent db636ee commit 2d8dce0

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

‎src/PhpParser/AstResolver.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ public function resolveClassMethodFromCall(MethodCall|StaticCall|NullsafeMethodC
139139
return $this->resolveClassMethod($className, MethodName::CONSTRUCT);
140140
}
141141

142+
$methodName = $this->nodeNameResolver->getName($call->name);
143+
if ($methodName === null) {
144+
return null;
145+
}
146+
142147
$callerStaticType = ($call instanceof MethodCall || $call instanceof NullsafeMethodCall)
143148
? $this->nodeTypeResolver->getType($call->var)
144149
: $this->nodeTypeResolver->getType($call->class);
@@ -148,11 +153,6 @@ public function resolveClassMethodFromCall(MethodCall|StaticCall|NullsafeMethodC
148153
return null;
149154
}
150155

151-
$methodName = $this->nodeNameResolver->getName($call->name);
152-
if ($methodName === null) {
153-
return null;
154-
}
155-
156156
return $this->resolveClassMethod($className, $methodName);
157157
}
158158

‎src/Reflection/ReflectionResolver.php‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public function resolveMethodReflection(string $className, string $methodName, ?
138138

139139
public function resolveMethodReflectionFromStaticCall(StaticCall $staticCall): ?MethodReflection
140140
{
141+
$methodName = $this->nodeNameResolver->getName($staticCall->name);
142+
if ($methodName === null) {
143+
return null;
144+
}
145+
141146
$objectType = $this->nodeTypeResolver->getType($staticCall->class);
142147

143148
if ($objectType instanceof ShortenedObjectType || $objectType instanceof AliasedObjectType) {
@@ -148,11 +153,6 @@ public function resolveMethodReflectionFromStaticCall(StaticCall $staticCall): ?
148153
$classNames = $objectType->getObjectClassNames();
149154
}
150155

151-
$methodName = $this->nodeNameResolver->getName($staticCall->name);
152-
if ($methodName === null) {
153-
return null;
154-
}
155-
156156
$scope = $staticCall->getAttribute(AttributeKey::SCOPE);
157157

158158
foreach ($classNames as $className) {
@@ -167,20 +167,18 @@ public function resolveMethodReflectionFromStaticCall(StaticCall $staticCall): ?
167167

168168
public function resolveMethodReflectionFromMethodCall(MethodCall $methodCall): ?MethodReflection
169169
{
170-
$callerType = $this->nodeTypeResolver->getType($methodCall->var);
170+
$methodName = $this->nodeNameResolver->getName($methodCall->name);
171+
if ($methodName === null) {
172+
return null;
173+
}
171174

175+
$callerType = $this->nodeTypeResolver->getType($methodCall->var);
172176
if ($callerType instanceof BenevolentUnionType) {
173177
$callerType = TypeCombinator::removeFalsey($callerType);
174178
}
175179

176180
$className = ClassNameFromObjectTypeResolver::resolve($callerType);
177181
if ($className === null) {
178-
179-
return null;
180-
}
181-
182-
$methodName = $this->nodeNameResolver->getName($methodCall->name);
183-
if ($methodName === null) {
184182
return null;
185183
}
186184

0 commit comments

Comments
 (0)