Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PropertyInfo] Fixed type extraction for nullable collections of non-nullable elements #34165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function typesProvider()
['h', [new Type(Type::BUILTIN_TYPE_STRING, true)], null, null],
['i', [new Type(Type::BUILTIN_TYPE_STRING, true), new Type(Type::BUILTIN_TYPE_INT, true)], null, null],
['j', [new Type(Type::BUILTIN_TYPE_OBJECT, true, 'DateTime')], null, null],
['nullableCollectionOfNonNullableElements', [new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_INT, false))], null, null],
['donotexist', null, null, null],
['staticGetter', null, null, null],
['staticSetter', null, null, null],
Expand Down Expand Up @@ -174,6 +175,7 @@ public function typesWithCustomPrefixesProvider()
['h', [new Type(Type::BUILTIN_TYPE_STRING, true)], null, null],
['i', [new Type(Type::BUILTIN_TYPE_STRING, true), new Type(Type::BUILTIN_TYPE_INT, true)], null, null],
['j', [new Type(Type::BUILTIN_TYPE_OBJECT, true, 'DateTime')], null, null],
['nullableCollectionOfNonNullableElements', [new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_INT, false))], null, null],
['donotexist', null, null, null],
['staticGetter', null, null, null],
['staticSetter', null, null, null],
Expand Down Expand Up @@ -214,6 +216,7 @@ public function typesWithNoPrefixesProvider()
['h', [new Type(Type::BUILTIN_TYPE_STRING, true)], null, null],
['i', [new Type(Type::BUILTIN_TYPE_STRING, true), new Type(Type::BUILTIN_TYPE_INT, true)], null, null],
['j', [new Type(Type::BUILTIN_TYPE_OBJECT, true, 'DateTime')], null, null],
['nullableCollectionOfNonNullableElements', [new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_INT, false))], null, null],
['donotexist', null, null, null],
['staticGetter', null, null, null],
['staticSetter', null, null, null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function testGetProperties()
'h',
'i',
'j',
'nullableCollectionOfNonNullableElements',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
Expand Down Expand Up @@ -97,6 +98,7 @@ public function testGetPropertiesWithCustomPrefixes()
'h',
'i',
'j',
'nullableCollectionOfNonNullableElements',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
Expand Down Expand Up @@ -133,6 +135,7 @@ public function testGetPropertiesWithNoPrefixes()
'h',
'i',
'j',
'nullableCollectionOfNonNullableElements',
'emptyVar',
'iteratorCollection',
'iteratorCollectionWithKey',
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class Dummy extends ParentDummy
*/
public $j;

/**
* @var int[]|null
*/
public $nullableCollectionOfNonNullableElements;

/**
* @var array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private function createType(DocType $type, bool $nullable, string $docType = nul
$collectionValueType = null;
} else {
$collectionKeyType = new Type(Type::BUILTIN_TYPE_INT);
$collectionValueType = $this->createType($type, $nullable, substr($docType, 0, -2));
$collectionValueType = $this->createType($type, false, substr($docType, 0, -2));
}

return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, $collectionKeyType, $collectionValueType);
Expand Down