Allow multidimensional collection in property info
This commit is contained in:
parent
9bfa971bc5
commit
6331687f65
|
@ -319,28 +319,26 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
|
|||
{
|
||||
// Cannot guess
|
||||
if (!$docType || 'mixed' === $docType) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($collection = '[]' === substr($docType, -2)) {
|
||||
$docType = substr($docType, 0, -2);
|
||||
if ('[]' === substr($docType, -2)) {
|
||||
if ('mixed[]' === $docType) {
|
||||
$collectionKeyType = null;
|
||||
$collectionValueType = null;
|
||||
} else {
|
||||
$collectionKeyType = new Type(Type::BUILTIN_TYPE_INT);
|
||||
$collectionValueType = $this->createType(substr($docType, 0, -2), $nullable);
|
||||
}
|
||||
|
||||
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, $collectionKeyType, $collectionValueType);
|
||||
}
|
||||
|
||||
$docType = $this->normalizeType($docType);
|
||||
list($phpType, $class) = $this->getPhpTypeAndClass($docType);
|
||||
|
||||
$array = 'array' === $docType;
|
||||
|
||||
if ($collection || $array) {
|
||||
if ($array || 'mixed' === $docType) {
|
||||
$collectionKeyType = null;
|
||||
$collectionValueType = null;
|
||||
} else {
|
||||
$collectionKeyType = new Type(Type::BUILTIN_TYPE_INT);
|
||||
$collectionValueType = new Type($phpType, $nullable, $class);
|
||||
}
|
||||
|
||||
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, $collectionKeyType, $collectionValueType);
|
||||
if ('array' === $docType) {
|
||||
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, null, null);
|
||||
}
|
||||
|
||||
return new Type($phpType, $nullable, $class);
|
||||
|
|
|
@ -62,6 +62,8 @@ class PhpDocExtractorTest extends TestCase
|
|||
array('bal', array(new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')), null, null),
|
||||
array('parent', array(new Type(Type::BUILTIN_TYPE_OBJECT, false, 'Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy')), null, null),
|
||||
array('collection', 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('mixedCollection', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, null, null)), null, null),
|
||||
array('nestedCollection', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING, false)))), null, null),
|
||||
array('a', array(new Type(Type::BUILTIN_TYPE_INT)), 'A.', null),
|
||||
array('b', array(new Type(Type::BUILTIN_TYPE_OBJECT, true, 'Symfony\Component\PropertyInfo\Tests\Fixtures\ParentDummy')), 'B.', null),
|
||||
array('c', array(new Type(Type::BUILTIN_TYPE_BOOL, true)), null, null),
|
||||
|
|
|
@ -37,6 +37,8 @@ class ReflectionExtractorTest extends TestCase
|
|||
'bal',
|
||||
'parent',
|
||||
'collection',
|
||||
'nestedCollection',
|
||||
'mixedCollection',
|
||||
'B',
|
||||
'Guid',
|
||||
'g',
|
||||
|
|
|
@ -46,6 +46,16 @@ class Dummy extends ParentDummy
|
|||
*/
|
||||
public $collection;
|
||||
|
||||
/**
|
||||
* @var string[][]
|
||||
*/
|
||||
public $nestedCollection;
|
||||
|
||||
/**
|
||||
* @var mixed[]
|
||||
*/
|
||||
public $mixedCollection;
|
||||
|
||||
/**
|
||||
* @var ParentDummy
|
||||
*/
|
||||
|
|
Reference in New Issue