Skip to content

Commit

Permalink
Merge pull request #14 from veewee/getproperty-speed
Browse files Browse the repository at this point in the history
Introduce native function invocation rule + Speed up finding a single…
  • Loading branch information
veewee authored Jun 13, 2024
2 parents 93e22ef + 065e21e commit 627d428
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 4 deletions.
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

0 comments on commit 627d428

Please sign in to comment.