Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce native function invocation rule + Speed up finding a single… #14

Merged
merged 1 commit into from
Jun 13, 2024
Merged
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
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
'native_function_invocation' => true,
])
;
1 change: 1 addition & 0 deletions src/ArrayAccess/index_get.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace VeeWee\Reflecta\ArrayAccess;

use VeeWee\Reflecta\ArrayAccess\Exception\ArrayAccessException;
use function array_key_exists;

/**
* @pure
Expand Down
12 changes: 8 additions & 4 deletions src/Reflect/Type/ReflectedClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Lens/LensTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Lens/OptionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Reflect/ClassAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Reflect/ClassHasAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Reflect/ClassIsDynamicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down