Allow multidimensional collection in property info
This commit is contained in:
parent
18edda3716
commit
ce49036790
@ -87,6 +87,8 @@ class PhpDocExtractorTest extends TestCase
|
|||||||
array('bal', array(new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')), null, null),
|
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('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('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('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('mixedCollection', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, null, null)), null, null),
|
||||||
array('a', array(new Type(Type::BUILTIN_TYPE_INT)), 'A.', 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('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),
|
array('c', array(new Type(Type::BUILTIN_TYPE_BOOL, true)), null, null),
|
||||||
@ -126,6 +128,8 @@ class PhpDocExtractorTest extends TestCase
|
|||||||
array('bal', array(new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')), null, null),
|
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('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('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('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('mixedCollection', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, null, null)), null, null),
|
||||||
array('a', null, 'A.', null),
|
array('a', null, 'A.', null),
|
||||||
array('b', null, 'B.', null),
|
array('b', null, 'B.', null),
|
||||||
array('c', array(new Type(Type::BUILTIN_TYPE_BOOL, true)), null, null),
|
array('c', array(new Type(Type::BUILTIN_TYPE_BOOL, true)), null, null),
|
||||||
@ -164,6 +168,8 @@ class PhpDocExtractorTest extends TestCase
|
|||||||
array('bal', array(new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')), null, null),
|
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('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('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('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('mixedCollection', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, null, null)), null, null),
|
||||||
array('a', null, 'A.', null),
|
array('a', null, 'A.', null),
|
||||||
array('b', null, 'B.', null),
|
array('b', null, 'B.', null),
|
||||||
array('c', null, null, null),
|
array('c', null, null, null),
|
||||||
|
@ -38,6 +38,8 @@ class ReflectionExtractorTest extends TestCase
|
|||||||
'bal',
|
'bal',
|
||||||
'parent',
|
'parent',
|
||||||
'collection',
|
'collection',
|
||||||
|
'nestedCollection',
|
||||||
|
'mixedCollection',
|
||||||
'B',
|
'B',
|
||||||
'Guid',
|
'Guid',
|
||||||
'g',
|
'g',
|
||||||
@ -77,6 +79,8 @@ class ReflectionExtractorTest extends TestCase
|
|||||||
'bal',
|
'bal',
|
||||||
'parent',
|
'parent',
|
||||||
'collection',
|
'collection',
|
||||||
|
'nestedCollection',
|
||||||
|
'mixedCollection',
|
||||||
'B',
|
'B',
|
||||||
'Guid',
|
'Guid',
|
||||||
'g',
|
'g',
|
||||||
@ -108,6 +112,8 @@ class ReflectionExtractorTest extends TestCase
|
|||||||
'bal',
|
'bal',
|
||||||
'parent',
|
'parent',
|
||||||
'collection',
|
'collection',
|
||||||
|
'nestedCollection',
|
||||||
|
'mixedCollection',
|
||||||
'B',
|
'B',
|
||||||
'Guid',
|
'Guid',
|
||||||
'g',
|
'g',
|
||||||
|
@ -45,6 +45,14 @@ class Dummy extends ParentDummy
|
|||||||
* @Groups({"a", "b"})
|
* @Groups({"a", "b"})
|
||||||
*/
|
*/
|
||||||
public $collection;
|
public $collection;
|
||||||
|
/**
|
||||||
|
* @var string[][]
|
||||||
|
*/
|
||||||
|
public $nestedCollection;
|
||||||
|
/**
|
||||||
|
* @var mixed[]
|
||||||
|
*/
|
||||||
|
public $mixedCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ParentDummy
|
* @var ParentDummy
|
||||||
|
@ -89,28 +89,26 @@ final class PhpDocTypeHelper
|
|||||||
{
|
{
|
||||||
// Cannot guess
|
// Cannot guess
|
||||||
if (!$docType || 'mixed' === $docType) {
|
if (!$docType || 'mixed' === $docType) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($collection = '[]' === substr($docType, -2)) {
|
if ('[]' === substr($docType, -2)) {
|
||||||
$docType = substr($docType, 0, -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);
|
$docType = $this->normalizeType($docType);
|
||||||
list($phpType, $class) = $this->getPhpTypeAndClass($docType);
|
list($phpType, $class) = $this->getPhpTypeAndClass($docType);
|
||||||
|
|
||||||
$array = 'array' === $docType;
|
if ('array' === $docType) {
|
||||||
|
return new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true, null, null);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Type($phpType, $nullable, $class);
|
return new Type($phpType, $nullable, $class);
|
||||||
|
Reference in New Issue
Block a user