From e1a794b3ae27f157f461ba6aafdf7f6d53168258 Mon Sep 17 00:00:00 2001 From: Ady <40644941+adynemo@users.noreply.github.com> Date: Fri, 31 Oct 2025 11:34:14 -0400 Subject: [PATCH] Add hasser as property accessor --- src/Utils/PropertyAccessor.php | 2 +- tests/Fixtures/Types/GetterSetterType.php | 6 ++++++ tests/Utils/PropertyAccessorTest.php | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Utils/PropertyAccessor.php b/src/Utils/PropertyAccessor.php index 1347d1151c..7b16683d11 100644 --- a/src/Utils/PropertyAccessor.php +++ b/src/Utils/PropertyAccessor.php @@ -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)) { diff --git a/tests/Fixtures/Types/GetterSetterType.php b/tests/Fixtures/Types/GetterSetterType.php index cb11a7e3cf..48330de537 100644 --- a/tests/Fixtures/Types/GetterSetterType.php +++ b/tests/Fixtures/Types/GetterSetterType.php @@ -15,6 +15,7 @@ public function __construct( public bool $three = false, #[Field] public string $four = '', + public bool $five = true, ) { } @@ -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'); diff --git a/tests/Utils/PropertyAccessorTest.php b/tests/Utils/PropertyAccessorTest.php index 6d1ed84723..ac4005c746 100644 --- a/tests/Utils/PropertyAccessorTest.php +++ b/tests/Utils/PropertyAccessorTest.php @@ -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']; } @@ -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'];