bug #22251 [PropertyInfo] Support nullable array or collection (4rthem)

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
-------

74ee588924 support nullable array or collection
This commit is contained in:
Kévin Dunglas 2017-04-03 22:48:36 +02:00
commit 80cea46ff1
No known key found for this signature in database
GPG Key ID: 4D04EBEF06AAF3A6
4 changed files with 12 additions and 3 deletions

View File

@ -242,7 +242,7 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
* @param string $ucFirstProperty
* @param int $type
*
* @return DocBlock|null
* @return array|null
*/
private function getDocBlockFromMethod($class, $ucFirstProperty, $type)
{
@ -337,10 +337,10 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
$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);

View File

@ -68,6 +68,7 @@ class PhpDocExtractorTest extends TestCase
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),

View File

@ -38,6 +38,7 @@ class ReflectionExtractorTest extends TestCase
'parent',
'collection',
'B',
'g',
'foo',
'foo2',
'foo3',

View File

@ -51,6 +51,13 @@ class Dummy extends ParentDummy
*/
public $B;
/**
* Nullable array.
*
* @var array|null
*/
public $g;
public static function getStatic()
{
}