Skip to content

Commit e1a794b

Browse files
authored
Add hasser as property accessor
1 parent cb7c195 commit e1a794b

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/Utils/PropertyAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PropertyAccessor
2222
*/
2323
public static function findGetter(string $class, string $propertyName): string|null
2424
{
25-
foreach (['get', 'is'] as $prefix) {
25+
foreach (['get', 'is', 'has'] as $prefix) {
2626
$methodName = self::propertyToMethodName($prefix, $propertyName);
2727

2828
if (self::isPublicMethod($class, $methodName)) {

tests/Fixtures/Types/GetterSetterType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct(
1515
public bool $three = false,
1616
#[Field]
1717
public string $four = '',
18+
public bool $five = true,
1819
)
1920
{
2021
}
@@ -39,6 +40,11 @@ private function getFour(string $arg = ''): string
3940
throw new \RuntimeException('Should not be called');
4041
}
4142

43+
public function hasFive(string $arg = ''): bool
44+
{
45+
return $arg === 'foo';
46+
}
47+
4248
private function setFour(string $value, string $arg): void
4349
{
4450
throw new \RuntimeException('Should not be called');

tests/Utils/PropertyAccessorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static function findGetterProvider(): iterable
2626
yield 'regular property' => [null, MagicGetterSetterType::class, 'one'];
2727
yield 'getter' => ['getTwo', MagicGetterSetterType::class, 'two'];
2828
yield 'isser' => ['isThree', MagicGetterSetterType::class, 'three'];
29+
yield 'hasser' => ['hasFive', MagicGetterSetterType::class, 'five'];
2930
yield 'private getter' => [null, MagicGetterSetterType::class, 'four'];
3031
yield 'undefined property' => [null, MagicGetterSetterType::class, 'twenty'];
3132
}
@@ -60,6 +61,8 @@ public static function getValueProvider(): iterable
6061
yield 'getter' => ['result', new MagicGetterSetterType(), 'two', ['result']];
6162
yield 'isser #1' => [true, new MagicGetterSetterType(), 'three', ['foo']];
6263
yield 'isser #2' => [false, new MagicGetterSetterType(), 'three', ['bar']];
64+
yield 'hasser #1' => [true, new MagicGetterSetterType(), 'five', ['foo']];
65+
yield 'hasser #2' => [false, new MagicGetterSetterType(), 'five', ['bar']];
6366
yield 'private getter' => ['result', new MagicGetterSetterType(four: 'result'), 'four'];
6467
yield 'magic getter' => ['magic', new MagicGetterSetterType(), 'twenty'];
6568
yield 'undefined property' => [AccessPropertyException::createForUnreadableProperty(GetterSetterType::class, 'twenty'), new GetterSetterType(), 'twenty'];

0 commit comments

Comments
 (0)