Skip to content

Commit

Permalink
[Reflection] Clean up unnecessary loop parents on ReflectionResolver (
Browse files Browse the repository at this point in the history
…#6146)

* [Reflection] Clean up unnecessary loop on ReflectionResolver

* more clean up
  • Loading branch information
samsonasik committed Jul 14, 2024
1 parent 4dd889a commit a9ddf8f
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions src/Reflection/ReflectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,8 @@ public function resolveClassReflectionSourceObject(
return $classReflection;
}

$nativeReflection = $classReflection->getNativeReflection();
$properties = $nativeReflection->getProperties();
// no need to lookup properties on interfaces
$ancestors = $classReflection->getParents();

foreach ($properties as $property) {
if ($property->getName() !== $propertyName) {
continue;
}

if ($property->getDeclaringClass()->getName() === $className) {
return $classReflection;
}

foreach ($ancestors as $ancestor) {
if ($ancestor->hasNativeProperty($propertyName)) {
return $ancestor;
}
}
if ($this->reflectionProvider->hasClass($property->getDeclaringClass()->getName())) {
return $this->reflectionProvider->getClass($property->getDeclaringClass()->getName());
}

return $classReflection;
Expand All @@ -140,24 +123,8 @@ public function resolveClassReflectionSourceObject(
return $classReflection;
}

$nativeReflection = $classReflection->getNativeReflection();
$methods = $nativeReflection->getMethods();
$ancestors = [...$classReflection->getParents(), ...$classReflection->getInterfaces()];

foreach ($methods as $method) {
if ($method->getName() !== $methodName) {
continue;
}

if ($method->getDeclaringClass()->getName() === $className) {
return $classReflection;
}

foreach ($ancestors as $ancestor) {
if ($ancestor->hasNativeMethod($methodName)) {
return $ancestor;
}
}
if ($this->reflectionProvider->hasClass($extendedMethodReflection->getDeclaringClass()->getName())) {
return $this->reflectionProvider->getClass($extendedMethodReflection->getDeclaringClass()->getName());
}

return $classReflection;
Expand Down

0 comments on commit a9ddf8f

Please sign in to comment.