Skip to content

Commit dbee4b5

Browse files
committed
Made ParentClass reflection resolving lazier
1 parent 6754c23 commit dbee4b5

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

src/Reflection/Annotations/AnnotationsMethodsClassReflectionExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ private function findClassReflectionWithMethod(
8484
return $methodWithDeclaringClass;
8585
}
8686

87-
foreach ($classReflection->getParents() as $parentClass) {
87+
$parentClass = $classReflection->getParentClass();
88+
while ($parentClass !== null) {
8889
$methodWithDeclaringClass = $this->findClassReflectionWithMethod($parentClass, $parentClass, $methodName);
8990
if ($methodWithDeclaringClass === null) {
9091
foreach ($parentClass->getTraits() as $traitClass) {
@@ -95,6 +96,9 @@ private function findClassReflectionWithMethod(
9596

9697
return $parentTraitMethodWithDeclaringClass;
9798
}
99+
100+
$parentClass = $parentClass->getParentClass();
101+
98102
continue;
99103
}
100104

src/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ private function findClassReflectionWithProperty(
7474
return $methodWithDeclaringClass;
7575
}
7676

77-
foreach ($classReflection->getParents() as $parentClass) {
77+
$parentClass = $classReflection->getParentClass();
78+
while ($parentClass !== null) {
7879
$methodWithDeclaringClass = $this->findClassReflectionWithProperty($parentClass, $parentClass, $propertyName);
7980
if ($methodWithDeclaringClass === null) {
8081
foreach ($parentClass->getTraits() as $traitClass) {
@@ -85,6 +86,9 @@ private function findClassReflectionWithProperty(
8586

8687
return $parentTraitMethodWithDeclaringClass;
8788
}
89+
90+
$parentClass = $parentClass->getParentClass();
91+
8892
continue;
8993
}
9094

src/Reflection/Mixin/MixinMethodsClassReflectionExtension.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ private function findMethod(ClassReflection $classReflection, string $methodName
7474
return new MixinMethodReflection($method, $static);
7575
}
7676

77-
foreach ($classReflection->getParents() as $parentClass) {
77+
$parentClass = $classReflection->getParentClass();
78+
while ($parentClass !== null) {
7879
$method = $this->findMethod($parentClass, $methodName);
79-
if ($method === null) {
80-
continue;
80+
if ($method !== null) {
81+
return $method;
8182
}
8283

83-
return $method;
84+
$parentClass = $parentClass->getParentClass();
8485
}
8586

8687
return null;

src/Reflection/Mixin/MixinPropertiesClassReflectionExtension.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ private function findProperty(ClassReflection $classReflection, string $property
6565
return $property;
6666
}
6767

68-
foreach ($classReflection->getParents() as $parentClass) {
68+
$parentClass = $classReflection->getParentClass();
69+
while ($parentClass !== null) {
6970
$property = $this->findProperty($parentClass, $propertyName);
70-
if ($property === null) {
71-
continue;
71+
if ($property !== null) {
72+
return $property;
7273
}
7374

74-
return $property;
75+
$parentClass = $parentClass->getParentClass();
7576
}
7677

7778
return null;

0 commit comments

Comments
 (0)