Moved the type separation into ReturnTag, for consistency with the type merging that is currently there.

This commit is contained in:
Vasil Rangelov
2012-11-16 21:43:25 +02:00
parent cdaa97eb31
commit db20ae39fb
3 changed files with 25 additions and 29 deletions
@@ -53,7 +53,7 @@ class ReturnTag extends Tag
public function getTypes()
{
$types = new \phpDocumentor\Reflection\DocBlock\Type\Collection(
array($this->type),
explode('|', $this->type),
$this->docblock ? $this->docblock->getNamespace() : null,
$this->docblock ? $this->docblock->getNamespaceAliases() : array()
);
@@ -22,9 +22,6 @@ namespace phpDocumentor\Reflection\DocBlock\Type;
*/
class Collection extends \ArrayObject
{
/** @var string Definition of the OR operator for types */
const OPERATOR_OR = '|';
/** @var string Definition of the ARRAY operator for types */
const OPERATOR_ARRAY = '[]';
@@ -167,16 +164,11 @@ class Collection extends \ArrayObject
.var_export($type, true)
);
}
// separate the type by the OR operator
$type_parts = explode(self::OPERATOR_OR, $type);
foreach ($type_parts as $part) {
$expanded_type = $this->expand($part);
$expanded_type = $this->expand($type);
if ($expanded_type) {
$this[] = $expanded_type;
}
}
}
/**
* Analyzes the given type and returns the FQCN variant.
@@ -148,7 +148,9 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
$collection = new Collection();
$collection->setNamespace('\My\Space');
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
$collection->add($fixture);
foreach ($fixture as $type) {
$collection->add($type);
}
$this->assertSame($expected, $collection->getArrayCopy());
}
@@ -166,7 +168,9 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
{
$collection = new Collection();
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
$collection->add($fixture);
foreach ($fixture as $type) {
$collection->add($type);
}
$this->assertSame($expected, $collection->getArrayCopy());
}
@@ -195,34 +199,34 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
public function provideTypesToExpand($method, $namespace = '\My\Space\\')
{
return array(
array('', array()),
array(' ', array()),
array('int', array('int')),
array('int ', array('int')),
array('string', array('string')),
array('DocBlock', array($namespace.'DocBlock')),
array('DocBlock[]', array($namespace.'DocBlock[]')),
array(' DocBlock ', array($namespace.'DocBlock')),
array('\My\Space\DocBlock', array('\My\Space\DocBlock')),
array('Alias\DocBlock', array('\My\Space\Aliasing\DocBlock')),
array(array(''), array()),
array(array(' '), array()),
array(array('int'), array('int')),
array(array('int '), array('int')),
array(array('string'), array('string')),
array(array('DocBlock'), array($namespace.'DocBlock')),
array(array('DocBlock[]'), array($namespace.'DocBlock[]')),
array(array(' DocBlock '), array($namespace.'DocBlock')),
array(array('\My\Space\DocBlock'), array('\My\Space\DocBlock')),
array(array('Alias\DocBlock'), array('\My\Space\Aliasing\DocBlock')),
array(
'DocBlock|Tag',
array('DocBlock', 'Tag'),
array($namespace .'DocBlock', $namespace .'Tag')
),
array(
'DocBlock|null',
array('DocBlock', 'null'),
array($namespace.'DocBlock', 'null')
),
array(
'\My\Space\DocBlock|Tag',
array('\My\Space\DocBlock', 'Tag'),
array('\My\Space\DocBlock', $namespace.'Tag')
),
array(
'DocBlock[]|null',
array('DocBlock[]', 'null'),
array($namespace.'DocBlock[]', 'null')
),
array(
'DocBlock[]|int[]',
array('DocBlock[]', 'int[]'),
array($namespace.'DocBlock[]', 'int[]')
),
);