8000 [PropertyInfo] Support nullable array or collection by 4rthem · Pull Request #22251 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyInfo] Support nullable array or collection #22251

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
merged 1 commit into from
Apr 3, 2017
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
support nullable array or collection
  • Loading branch information
4rthem committed Apr 3, 2017
commit 74ee588924cf2e88a5c64d48d6e6ea1283b77bdc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private function getDocBlockFromProperty($class, $property)
* @param string $ucFirstProperty
* @param int $type
*
* @return DocBlock|null
* @return array|null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be reverted (this method returns an instance of DocBlock, not an array).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to expand the code :)

Look at the line 287

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, indeed it's ok.

*/
private function getDocBlockFromMethod($class, $ucFirstProperty, $type)
{
Expand Down Expand Up @@ -337,10 +337,10 @@ private function createType($docType, $nullable)
$collectionValueType = null;
} else {
$collectionKeyType = new Type(Type::BUILTIN_TYPE_INT);
$collectionValueType = new Type($phpType, false, $class);
$collectionValueType = new Type($phpType, $nullable, $class);
}

return new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, $collectionKeyType, $collectionValueType);
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, $collectionKeyType, $collectionValueType);
}

return new Type($phpType, $nullable, $class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function typesProvider()
array('d', array(new Type(Type::BUILTIN_TYPE_BOOL)), null, null),
array('e', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_RESOURCE))), null, null),
array('f', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime'))), null, null),
array('g', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true)), 'Nullable array.', null),
array('donotexist', null, null, null),
array('staticGetter', null, null, null),
array('staticSetter', null, null, null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function testGetProperties()
'parent',
'collection',
'B',
'g',
'foo',
'foo2',
'foo3',
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class Dummy extends ParentDummy
*/
public $B;

/**
* Nullable array.
*
* @var array|null
*/
public $g;

public static function getStatic()
{
}
Expand Down
0