Skip to content

Commit

Permalink
Allow @property and @method to override above the same class
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 7, 2023
1 parent 9c72fc1 commit 3467a21
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private function createProperty(
throw new ShouldNotHappenException();
}

if ($hierarchyDistances[$annotationProperty->getDeclaringClass()->getName()] < $hierarchyDistances[$distanceDeclaringClass]) {
if ($hierarchyDistances[$annotationProperty->getDeclaringClass()->getName()] <= $hierarchyDistances[$distanceDeclaringClass]) {
return $annotationProperty;
}
}
Expand Down Expand Up @@ -468,7 +468,7 @@ private function createMethod(
throw new ShouldNotHappenException();
}

if ($hierarchyDistances[$annotationMethod->getDeclaringClass()->getName()] < $hierarchyDistances[$distanceDeclaringClass]) {
if ($hierarchyDistances[$annotationMethod->getDeclaringClass()->getName()] <= $hierarchyDistances[$distanceDeclaringClass]) {
return $annotationMethod;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/bug-3142.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function sayHello()
function (): void {
$hw = new HelloWorld();
assertType('string', $hw->sayHi());
assertType('int', $hw->sayHello());
assertType('string', $hw->sayHello());
};

interface DecoratorInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public function dataMethods(): array
],
'conflictingMethod' => [
'class' => Bar::class,
'returnType' => Bar::class,
'returnType' => Foo::class,
'isStatic' => false,
'isVariadic' => false,
'parameters' => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public function dataProperties(): array
],
'conflictingAnnotationProperty' => [
'class' => Bar::class,
'readableType' => Bar::class,
'writableType' => Bar::class,
'readableType' => Foo::class,
'writableType' => Foo::class,
'writable' => true,
'readable' => true,
],
Expand Down

0 comments on commit 3467a21

Please sign in to comment.