Skip to content

Commit 33d37e5

Browse files
committed
Fix no collection in extract default value
1 parent 2b206ff commit 33d37e5

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,9 @@ private function extractFromDefaultValue(string $class, string $property): ?arra
477477
}
478478

479479
$type = \gettype($defaultValue);
480+
$type = static::MAP_TYPES[$type] ?? $type;
480481

481-
return [new Type(static::MAP_TYPES[$type] ?? $type)];
482+
return [new Type($type, false, null, Type::BUILTIN_TYPE_ARRAY === $type)];
482483
}
483484

484485
private function extractFromReflectionType(\ReflectionType $reflectionType, \ReflectionClass $declaringClass): array

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function defaultValueProvider()
257257
['defaultInt', [new Type(Type::BUILTIN_TYPE_INT, false)]],
258258
['defaultFloat', [new Type(Type::BUILTIN_TYPE_FLOAT, false)]],
259259
['defaultString', [new Type(Type::BUILTIN_TYPE_STRING, false)]],
260-
['defaultArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false)]],
260+
['defaultArray', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]],
261261
['defaultNull', null],
262262
];
263263
}
@@ -415,6 +415,7 @@ public function testTypedProperties(): void
415415
$this->assertEquals([new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)], $this->extractor->getTypes(Php74Dummy::class, 'dummy'));
416416
$this->assertEquals([new Type(Type::BUILTIN_TYPE_BOOL, true)], $this->extractor->getTypes(Php74Dummy::class, 'nullableBoolProp'));
417417
$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'));
418+
$this->assertEquals([new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)], $this->extractor->getTypes(Php74Dummy::class, 'collection'));
418419
}
419420

420421
/**

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php74Dummy.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Php74Dummy
2020
private ?bool $nullableBoolProp;
2121
/** @var string[] */
2222
private array $stringCollection;
23+
public array $collection = [];
2324

2425
public function addStringCollection(string $string): void
2526
{

0 commit comments

Comments
 (0)