diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 9c8aea9..76d2d27 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -53,5 +53,6 @@ 'static_lambda' => true, 'strict_comparison' => true, 'strict_param' => true, + 'native_function_invocation' => true, ]) ; diff --git a/src/ArrayAccess/index_get.php b/src/ArrayAccess/index_get.php index f6b7a93..6e5a9ee 100644 --- a/src/ArrayAccess/index_get.php +++ b/src/ArrayAccess/index_get.php @@ -3,6 +3,7 @@ namespace VeeWee\Reflecta\ArrayAccess; use VeeWee\Reflecta\ArrayAccess\Exception\ArrayAccessException; +use function array_key_exists; /** * @pure diff --git a/src/Reflect/Type/ReflectedClass.php b/src/Reflect/Type/ReflectedClass.php index 2f4a0c6..3133d60 100644 --- a/src/Reflect/Type/ReflectedClass.php +++ b/src/Reflect/Type/ReflectedClass.php @@ -12,6 +12,7 @@ use ReflectionProperty; use Throwable; use VeeWee\Reflecta\Reflect\Exception\UnreflectableException; +use function is_string; use function Psl\Dict\filter; use function Psl\Dict\reindex; use function Psl\Vec\map; @@ -125,12 +126,15 @@ public function docComment(): string public function property(string $property): ReflectedProperty { - $properties = $this->properties(); - if (!array_key_exists($property, $properties)) { - throw UnreflectableException::unknownProperty($this->fullName(), $property); + if ($this->class->hasProperty($property)) { + return new ReflectedProperty($this->class->getProperty($property)); } - return $properties[$property]; + if ($parent = $this->parent()->unwrapOr(null)) { + return $parent->property($property); + } + + throw UnreflectableException::unknownProperty($this->fullName(), $property); } /** diff --git a/tests/unit/Lens/LensTest.php b/tests/unit/Lens/LensTest.php index 499866d..357573f 100644 --- a/tests/unit/Lens/LensTest.php +++ b/tests/unit/Lens/LensTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use RuntimeException; use VeeWee\Reflecta\Lens\Lens; +use function array_key_exists; use function VeeWee\Reflecta\Lens\index; final class LensTest extends TestCase diff --git a/tests/unit/Lens/OptionalTest.php b/tests/unit/Lens/OptionalTest.php index d211917..f248bcf 100644 --- a/tests/unit/Lens/OptionalTest.php +++ b/tests/unit/Lens/OptionalTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use RuntimeException; use VeeWee\Reflecta\Lens\Lens; +use function array_key_exists; use function VeeWee\Reflecta\Lens\optional; final class OptionalTest extends TestCase diff --git a/tests/unit/Reflect/ClassAttributesTest.php b/tests/unit/Reflect/ClassAttributesTest.php index 005e429..e35e5d8 100644 --- a/tests/unit/Reflect/ClassAttributesTest.php +++ b/tests/unit/Reflect/ClassAttributesTest.php @@ -9,6 +9,7 @@ use VeeWee\Reflecta\TestFixtures\AbstractAttribute; use VeeWee\Reflecta\TestFixtures\CustomAttribute; use VeeWee\Reflecta\TestFixtures\InheritedCustomAttribute; +use function get_class; use function VeeWee\Reflecta\Reflect\class_attributes; final class ClassAttributesTest extends TestCase diff --git a/tests/unit/Reflect/ClassHasAttributeTest.php b/tests/unit/Reflect/ClassHasAttributeTest.php index 4ed3969..9bf8cbe 100644 --- a/tests/unit/Reflect/ClassHasAttributeTest.php +++ b/tests/unit/Reflect/ClassHasAttributeTest.php @@ -7,6 +7,7 @@ use VeeWee\Reflecta\TestFixtures\AbstractAttribute; use VeeWee\Reflecta\TestFixtures\CustomAttribute; use VeeWee\Reflecta\TestFixtures\InheritedCustomAttribute; +use function get_class; use function VeeWee\Reflecta\Reflect\class_has_attribute; final class ClassHasAttributeTest extends TestCase diff --git a/tests/unit/Reflect/ClassIsDynamicTest.php b/tests/unit/Reflect/ClassIsDynamicTest.php index 2dc93a8..8e07b4e 100644 --- a/tests/unit/Reflect/ClassIsDynamicTest.php +++ b/tests/unit/Reflect/ClassIsDynamicTest.php @@ -6,6 +6,7 @@ use AllowDynamicProperties; use PHPUnit\Framework\TestCase; use stdClass; +use function get_class; use function VeeWee\Reflecta\Reflect\class_is_dynamic; use const PHP_VERSION_ID;