Skip to content

Commit 3467a21

Browse files
committed
Allow @property and @method to override above the same class
1 parent 9c72fc1 commit 3467a21

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/Reflection/Php/PhpClassReflectionExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private function createProperty(
244244
throw new ShouldNotHappenException();
245245
}
246246

247-
if ($hierarchyDistances[$annotationProperty->getDeclaringClass()->getName()] < $hierarchyDistances[$distanceDeclaringClass]) {
247+
if ($hierarchyDistances[$annotationProperty->getDeclaringClass()->getName()] <= $hierarchyDistances[$distanceDeclaringClass]) {
248248
return $annotationProperty;
249249
}
250250
}
@@ -468,7 +468,7 @@ private function createMethod(
468468
throw new ShouldNotHappenException();
469469
}
470470

471-
if ($hierarchyDistances[$annotationMethod->getDeclaringClass()->getName()] < $hierarchyDistances[$distanceDeclaringClass]) {
471+
if ($hierarchyDistances[$annotationMethod->getDeclaringClass()->getName()] <= $hierarchyDistances[$distanceDeclaringClass]) {
472472
return $annotationMethod;
473473
}
474474
}

tests/PHPStan/Analyser/data/bug-3142.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function sayHello()
3535
function (): void {
3636
$hw = new HelloWorld();
3737
assertType('string', $hw->sayHi());
38-
assertType('int', $hw->sayHello());
38+
assertType('string', $hw->sayHello());
3939
};
4040

4141
interface DecoratorInterface

tests/PHPStan/Reflection/Annotations/AnnotationsMethodsClassReflectionExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public function dataMethods(): array
459459
],
460460
'conflictingMethod' => [
461461
'class' => Bar::class,
462-
'returnType' => Bar::class,
462+
'returnType' => Foo::class,
463463
'isStatic' => false,
464464
'isVariadic' => false,
465465
'parameters' => [],

tests/PHPStan/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtensionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public function dataProperties(): array
120120
],
121121
'conflictingAnnotationProperty' => [
122122
'class' => Bar::class,
123-
'readableType' => Bar::class,
124-
'writableType' => Bar::class,
123+
'readableType' => Foo::class,
124+
'writableType' => Foo::class,
125125
'writable' => true,
126126
'readable' => true,
127127
],

0 commit comments

Comments
 (0)