Skip to content

Commit

Permalink
Merge pull request #1478 from ondrejmirtes/fix-abstract-property
Browse files Browse the repository at this point in the history
Property from interface is abstract property
  • Loading branch information
Ocramius authored Jan 24, 2025
2 parents 56df7b3 + 67a41c7 commit c1326ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Reflection/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ public function isFinal(): bool

public function isAbstract(): bool
{
return (bool) ($this->modifiers & ReflectionPropertyAdapter::IS_ABSTRACT_COMPATIBILITY);
return (bool) ($this->modifiers & ReflectionPropertyAdapter::IS_ABSTRACT_COMPATIBILITY)
|| $this->declaringClass->isInterface();
}

public function isPromoted(): bool
Expand Down
5 changes: 5 additions & 0 deletions test/unit/Fixture/PropertyHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,8 @@ class FinalPropertyHooks
final set => strtolower($value);
}
}

interface InterfaceWithProperty
{
public int $abstractPropertyFromInterface { get; set; }
}
9 changes: 9 additions & 0 deletions test/unit/Reflection/ReflectionPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,15 @@ public function testIsAbstract(): void
self::assertTrue($hookProperty->isAbstract());
}

public function testIsAbstractInInterface(): void
{
$reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/PropertyHooks.php', $this->astLocator));
$classInfo = $reflector->reflectClass('Roave\BetterReflectionTest\Fixture\InterfaceWithProperty');

$abstractProperty = $classInfo->getProperty('abstractPropertyFromInterface');
self::assertTrue($abstractProperty->isAbstract());
}

public function testNoHooks(): void
{
$classInfo = $this->reflector->reflectClass(ExampleClass::class);
Expand Down

0 comments on commit c1326ba

Please sign in to comment.