Skip to content

Commit

Permalink
bug #22251 [PropertyInfo] Support nullable array or collection (4rthem)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.8 branch.

Discussion
----------

[PropertyInfo] Support nullable array or collection

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22248
| License       | MIT
| Doc PR        |

`@var array|null` was always considered as not nullable in the `PhpDocExtractor`.

Commits
-------

74ee588 support nullable array or collection
  • Loading branch information
dunglas committed Apr 3, 2017
2 parents d49005a + 74ee588 commit 80cea46
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Expand Up @@ -242,7 +242,7 @@ private function getDocBlockFromProperty($class, $property)
* @param string $ucFirstProperty
* @param int $type
*
* @return DocBlock|null
* @return array|null
*/
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
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
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
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 comments on commit 80cea46

Please sign in to comment.