From 33d37e56ba2d2b78c34257bcfa96ecb40d23cea6 Mon Sep 17 00:00:00 2001 From: Baptiste Leduc Date: Tue, 6 Oct 2020 20:00:06 +0200 Subject: [PATCH] Fix no collection in extract default value --- .../Component/PropertyInfo/Extractor/ReflectionExtractor.php | 3 ++- .../PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php | 3 ++- .../Component/PropertyInfo/Tests/Fixtures/Php74Dummy.php | 1 + 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 8c207cffc97f0..1d82948e69208 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -477,8 +477,9 @@ private function extractFromDefaultValue(string $class, string $property): ?arra } $type = \gettype($defaultValue); + $type = static::MAP_TYPES[$type] ?? $type; - return [new Type(static::MAP_TYPES[$type] ?? $type)]; + return [new Type($type, false, null, Type::BUILTIN_TYPE_ARRAY === $type)]; } private function extractFromReflectionType(\ReflectionType $reflectionType, \ReflectionClass $declaringClass): array diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php index a2d2db5b8000b..4e1fae4a35503 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php @@ -257,7 +257,7 @@ public function defaultValueProvider() ['defaultInt', [new Type(Type::BUILTIN_TYPE_INT, false)]], ['defaultFloat', [new Type(Type::BUILTIN_TYPE_FLOAT, false)]], ['defaultString', [new Type(Type::BUILTIN_TYPE_STRING, false)]], - ['defaultArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false)]], + ['defaultArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]], ['defaultNull', null], ]; } @@ -415,6 +415,7 @@ public function testTypedProperties(): void $this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)], $this->extractor->getTypes(Php74Dummy::class, 'dummy')); $this->assertEquals([new Type(Type::BUILTIN_TYPE_BOOL, true)], $this->extractor->getTypes(Php74Dummy::class, 'nullableBoolProp')); $this->assertEquals([new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING))], $this->extractor->getTypes(Php74Dummy::class, 'stringCollection')); + $this->assertEquals([new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)], $this->extractor->getTypes(Php74Dummy::class, 'collection')); } /** diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php74Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php74Dummy.php index ffc4f4cd37621..932b251b9560b 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php74Dummy.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php74Dummy.php @@ -20,6 +20,7 @@ class Php74Dummy private ?bool $nullableBoolProp; /** @var string[] */ private array $stringCollection; + public array $collection = []; public function addStringCollection(string $string): void { 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