From f146e72010a9b2bf4d842483b89ded1ce54f9a11 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 18 Jul 2022 10:30:40 +0200 Subject: [PATCH] Make sure nested composite types do not crash ReflectionExtractor --- .../PropertyInfo/Extractor/ReflectionExtractor.php | 5 +++++ .../Tests/Extractor/ReflectionExtractorTest.php | 6 +++++- .../Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index be22f95855b9e..a6e3738e7cb0c 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -334,6 +334,11 @@ private function extractFromReflectionType(\ReflectionType $reflectionType, \Ref $nullable = $reflectionType->allowsNull(); foreach (($reflectionType instanceof \ReflectionUnionType || $reflectionType instanceof \ReflectionIntersectionType) ? $reflectionType->getTypes() : [$reflectionType] as $type) { + if (!$type instanceof \ReflectionNamedType) { + // Nested composite types are not supported yet. + return []; + } + $phpTypeOrClass = $type->getName(); if ('null' === $phpTypeOrClass || 'mixed' === $phpTypeOrClass || 'never' === $phpTypeOrClass) { continue; diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php index 3f97527b720da..315171333d137 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php @@ -281,10 +281,14 @@ public function testExtractPhp82Type($property, array $type = null) $this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php82Dummy', $property, [])); } - public function php82TypesProvider() + public function php82TypesProvider(): iterable { yield ['nil', null]; yield ['false', [new Type(Type::BUILTIN_TYPE_FALSE)]]; + + // Nesting intersection and union types is not supported yet, + // but we should make sure this kind of composite types does not crash the extractor. + yield ['someCollection', null]; } /** diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php index b830fabf8842a..784c868369390 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php @@ -16,4 +16,6 @@ class Php82Dummy public null $nil = null; public false $false = false; + + public (\Traversable&\Countable)|null $someCollection = null; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy