bug #38446 [PropertyInfo] Extract from default value doesn't set collection boolean (Korbeil)
This PR was merged into the 5.1 branch.
Discussion
----------
[PropertyInfo] Extract from default value doesn't set collection boolean
| Q | A
| ------------- | ---
| Branch? | 5.1
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #38445
| License | MIT
| Doc PR | N/A
This PR will fix the issue by checking if the type is an array or not and setting the collection boolean based on this check.
Commits
-------
33d37e56ba
Fix no collection in extract default value
This commit is contained in:
commit
392f2e0ba2
@ -477,8 +477,9 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
||||
}
|
||||
|
||||
$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
|
||||
|
@ -257,7 +257,7 @@ class ReflectionExtractorTest extends TestCase
|
||||
['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 @@ class ReflectionExtractorTest extends TestCase
|
||||
$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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ class Php74Dummy
|
||||
private ?bool $nullableBoolProp;
|
||||
/** @var string[] */
|
||||
private array $stringCollection;
|
||||
public array $collection = [];
|
||||
|
||||
public function addStringCollection(string $string): void
|
||||
{
|
||||
|
Reference in New Issue
Block a user