diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a0bf837..f335728 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -22,6 +22,7 @@ tests/Test ./tests/TestPhp72 ./tests/TestPhp74 + ./tests/TestPhp80 ./tests/TestPhp81 ./tests/TestPhp82 diff --git a/src/Metadata/Driver/AnnotationsDriver.php b/src/Metadata/Driver/AnnotationsDriver.php index 8175bac..6109c45 100644 --- a/src/Metadata/Driver/AnnotationsDriver.php +++ b/src/Metadata/Driver/AnnotationsDriver.php @@ -151,9 +151,8 @@ private function getPropertyAnnotations(ReflectionProperty $property): array } // Adding php type if no precision has been added with annotation - if (PHP_VERSION_ID >= 70400 && $property->hasType() && !isset($annotations['type'])) { - /** @psalm-suppress UndefinedMethod */ - $annotations['type'] = $this->findType($property->getType()->getName(), $property); + if (PHP_VERSION_ID >= 70400 && ($type = $property->getType()) && $type instanceof \ReflectionNamedType && !isset($annotations['type'])) { + $annotations['type'] = $this->findType($type->getName(), $property); } return $annotations; diff --git a/tests/TestPhp80/Fixtures/with_union_type.php b/tests/TestPhp80/Fixtures/with_union_type.php new file mode 100644 index 0000000..6b3337a --- /dev/null +++ b/tests/TestPhp80/Fixtures/with_union_type.php @@ -0,0 +1,18 @@ +id = $id; + } + + public function id(): int|string + { + return $this->id; + } +} diff --git a/tests/TestPhp80/Metadata/Driver/AnnotationsDriverTest.php b/tests/TestPhp80/Metadata/Driver/AnnotationsDriverTest.php new file mode 100644 index 0000000..f7403a9 --- /dev/null +++ b/tests/TestPhp80/Metadata/Driver/AnnotationsDriverTest.php @@ -0,0 +1,37 @@ +getMetadataForClass($reflection); + + $this->assertInstanceOf(ClassMetadata::class, $metadata); + $this->assertEquals(WithUnionType::class, $metadata->name()); + + $this->assertEquals(Type::MIXED, $metadata->property('id')->type()->name()); + } +}