From 220f6d643211a427b0400db86e5c023c2420bab3 Mon Sep 17 00:00:00 2001 From: Luca Patera Date: Sun, 23 Nov 2025 19:21:03 +0100 Subject: [PATCH 1/2] fix: php 8.5 compatibility --- phpunit.xml.dist | 16 +++++++--------- src/Annotation/ConcreteResolver.php | 8 ++++++-- src/Annotation/UnionResolver.php | 8 ++++++-- src/Exception/InvalidValueException.php | 2 -- tests/HydratorTest.php | 12 ++++++------ 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index bc1022c..2f1573c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,14 @@ - - - - ./src - - + ./tests/ + + + ./src + + diff --git a/src/Annotation/ConcreteResolver.php b/src/Annotation/ConcreteResolver.php index 0838842..b921bd1 100644 --- a/src/Annotation/ConcreteResolver.php +++ b/src/Annotation/ConcreteResolver.php @@ -3,13 +3,14 @@ namespace SergiX44\Hydrator\Annotation; use Attribute; +use RuntimeException; /** * @Annotation * @Target({"CLASS"}) */ #[Attribute(Attribute::TARGET_CLASS)] -abstract class ConcreteResolver +class ConcreteResolver { protected array $concretes = []; @@ -19,7 +20,10 @@ abstract class ConcreteResolver * * @return string|null */ - abstract public function concreteFor(array $data, array $all): ?string; + public function concreteFor(array $data, array $all): ?string + { + throw new RuntimeException('This class is meant to be extended to provide your own ConcreteResolver logic.'); + } /** * @return array diff --git a/src/Annotation/UnionResolver.php b/src/Annotation/UnionResolver.php index baafec8..fa42aaf 100644 --- a/src/Annotation/UnionResolver.php +++ b/src/Annotation/UnionResolver.php @@ -6,13 +6,14 @@ use ReflectionException; use ReflectionNamedType; use ReflectionType; +use RuntimeException; /** * @Annotation * @Target({"PROPERTY"}) */ #[Attribute(Attribute::TARGET_PROPERTY)] -abstract class UnionResolver +class UnionResolver { /** * @param string $propertyName @@ -23,5 +24,8 @@ abstract class UnionResolver * * @return ReflectionType */ - abstract public function resolve(string $propertyName, array $propertyTypes, array $data): ReflectionType; + public function resolve(string $propertyName, array $propertyTypes, array $data): ReflectionType + { + throw new RuntimeException('This class is meant to be extended to provide your own UnionResolver logic.'); + } } diff --git a/src/Exception/InvalidValueException.php b/src/Exception/InvalidValueException.php index 0a1a68a..16b3024 100644 --- a/src/Exception/InvalidValueException.php +++ b/src/Exception/InvalidValueException.php @@ -4,7 +4,6 @@ use ReflectionProperty; use Throwable; - use function sprintf; class InvalidValueException extends HydrationException @@ -32,7 +31,6 @@ public function __construct( ) { parent::__construct($message, $code, $previous); - $property->setAccessible(false); $this->property = $property; } diff --git a/tests/HydratorTest.php b/tests/HydratorTest.php index 93bae7c..0f80f71 100644 --- a/tests/HydratorTest.php +++ b/tests/HydratorTest.php @@ -246,7 +246,7 @@ public function testHydrateBooleanProperty($value, $expected): void $this->assertSame($expected, $object->value); } - public function booleanValueProvider(): array + public static function booleanValueProvider(): array { return [ [true, true], @@ -280,7 +280,7 @@ public function testHydrateIntegerProperty($value, $expected): void $this->assertSame($expected, $object->value); } - public function integerValueProvider(): array + public static function integerValueProvider(): array { return [ [42, 42], @@ -306,7 +306,7 @@ public function testHydrateNumberProperty($value, $expected): void $this->assertSame($expected, $object->value); } - public function numberValueProvider(): array + public static function numberValueProvider(): array { return [ [42, 42.0], @@ -438,7 +438,7 @@ public function testHydrateDateTimeImmutableProperty($value, $expected): void $this->assertSame($expected, $object->value->format('Y-m-d')); } - public function timestampValueProvider(): array + public static function timestampValueProvider(): array { return [ [1262304000, '2010-01-01'], @@ -577,7 +577,7 @@ public function testHydrateStringableEnumProperty($value, $expected): void $this->assertSame($expected, $object->value); } - public function stringableEnumValueProvider(): array + public static function stringableEnumValueProvider(): array { return [ ['c1200a7e-136e-4a11-9bc3-cc937046e90f', Fixtures\StringableEnum::foo], @@ -615,7 +615,7 @@ public function testHydrateNumerableEnumProperty($value, $expected): void $this->assertSame($expected, $object->value); } - public function numerableEnumValueProvider(): array + public static function numerableEnumValueProvider(): array { return [ [1, Fixtures\NumerableEnum::foo], From c4cd9f6c6962f8ee8f23ff2b39499d29b6f25218 Mon Sep 17 00:00:00 2001 From: Luca Patera Date: Sun, 23 Nov 2025 18:21:23 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI [ci skip] [skip ci] --- src/Exception/InvalidValueException.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Exception/InvalidValueException.php b/src/Exception/InvalidValueException.php index 16b3024..51d4e6f 100644 --- a/src/Exception/InvalidValueException.php +++ b/src/Exception/InvalidValueException.php @@ -4,6 +4,7 @@ use ReflectionProperty; use Throwable; + use function sprintf; class InvalidValueException extends HydrationException