Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Utils/PropertyAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PropertyAccessor
*/
public static function findGetter(string $class, string $propertyName): string|null
{
foreach (['get', 'is'] as $prefix) {
foreach (['get', 'is', 'has'] as $prefix) {
$methodName = self::propertyToMethodName($prefix, $propertyName);

if (self::isPublicMethod($class, $methodName)) {
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixtures/Types/GetterSetterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function __construct(
public bool $three = false,
#[Field]
public string $four = '',
public bool $five = true,
)
{
}
Expand All @@ -39,6 +40,11 @@ private function getFour(string $arg = ''): string
throw new \RuntimeException('Should not be called');
}

public function hasFive(string $arg = ''): bool
{
return $arg === 'foo';
}

private function setFour(string $value, string $arg): void
{
throw new \RuntimeException('Should not be called');
Expand Down
3 changes: 3 additions & 0 deletions tests/Utils/PropertyAccessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static function findGetterProvider(): iterable
yield 'regular property' => [null, MagicGetterSetterType::class, 'one'];
yield 'getter' => ['getTwo', MagicGetterSetterType::class, 'two'];
yield 'isser' => ['isThree', MagicGetterSetterType::class, 'three'];
yield 'hasser' => ['hasFive', MagicGetterSetterType::class, 'five'];
yield 'private getter' => [null, MagicGetterSetterType::class, 'four'];
yield 'undefined property' => [null, MagicGetterSetterType::class, 'twenty'];
}
Expand Down Expand Up @@ -60,6 +61,8 @@ public static function getValueProvider(): iterable
yield 'getter' => ['result', new MagicGetterSetterType(), 'two', ['result']];
yield 'isser #1' => [true, new MagicGetterSetterType(), 'three', ['foo']];
yield 'isser #2' => [false, new MagicGetterSetterType(), 'three', ['bar']];
yield 'hasser #1' => [true, new MagicGetterSetterType(), 'five', ['foo']];
yield 'hasser #2' => [false, new MagicGetterSetterType(), 'five', ['bar']];
yield 'private getter' => ['result', new MagicGetterSetterType(four: 'result'), 'four'];
yield 'magic getter' => ['magic', new MagicGetterSetterType(), 'twenty'];
yield 'undefined property' => [AccessPropertyException::createForUnreadableProperty(GetterSetterType::class, 'twenty'), new GetterSetterType(), 'twenty'];
Expand Down
Loading