From be6432ee4c2a22ddbe2cfc884235caf09039278f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 12 Feb 2021 11:23:00 +0100 Subject: [PATCH] fix extracting mixed type-hinted property types --- .../Component/PropertyInfo/Extractor/ReflectionExtractor.php | 4 ++-- .../PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php | 1 + .../Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index 7b8687ee0b..c0f59cea9a 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -162,8 +162,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp try { $reflectionProperty = new \ReflectionProperty($class, $property); $type = $reflectionProperty->getType(); - if (null !== $type) { - return $this->extractFromReflectionType($type, $reflectionProperty->getDeclaringClass()); + if (null !== $type && $types = $this->extractFromReflectionType($type, $reflectionProperty->getDeclaringClass())) { + return $types; } } catch (\ReflectionException $e) { // noop diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php index 488cbe2e98..0a4f21da05 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php @@ -239,6 +239,7 @@ class ReflectionExtractorTest extends TestCase ['string', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Stringable'), new Type(Type::BUILTIN_TYPE_STRING)]], ['payload', null], ['data', null], + ['mixedProperty', null], ]; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php index 3e1ffba662..e8eac72be8 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php80Dummy.php @@ -4,6 +4,8 @@ namespace Symfony\Component\PropertyInfo\Tests\Fixtures; class Php80Dummy { + public mixed $mixedProperty; + public function getFoo(): array|null { }