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() public function getTypes()
{ {
$types = new \phpDocumentor\Reflection\DocBlock\Type\Collection( $types = new \phpDocumentor\Reflection\DocBlock\Type\Collection(
array($this->type), explode('|', $this->type),
$this->docblock ? $this->docblock->getNamespace() : null, $this->docblock ? $this->docblock->getNamespace() : null,
$this->docblock ? $this->docblock->getNamespaceAliases() : array() $this->docblock ? $this->docblock->getNamespaceAliases() : array()
); );
@@ -22,9 +22,6 @@ namespace phpDocumentor\Reflection\DocBlock\Type;
*/ */
class Collection extends \ArrayObject 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 */ /** @var string Definition of the ARRAY operator for types */
const OPERATOR_ARRAY = '[]'; const OPERATOR_ARRAY = '[]';
@@ -167,14 +164,9 @@ class Collection extends \ArrayObject
.var_export($type, true) .var_export($type, true)
); );
} }
$expanded_type = $this->expand($type);
// separate the type by the OR operator if ($expanded_type) {
$type_parts = explode(self::OPERATOR_OR, $type); $this[] = $expanded_type;
foreach ($type_parts as $part) {
$expanded_type = $this->expand($part);
if ($expanded_type) {
$this[] = $expanded_type;
}
} }
} }
@@ -148,7 +148,9 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
$collection = new Collection(); $collection = new Collection();
$collection->setNamespace('\My\Space'); $collection->setNamespace('\My\Space');
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing')); $collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
$collection->add($fixture); foreach ($fixture as $type) {
$collection->add($type);
}
$this->assertSame($expected, $collection->getArrayCopy()); $this->assertSame($expected, $collection->getArrayCopy());
} }
@@ -166,7 +168,9 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
{ {
$collection = new Collection(); $collection = new Collection();
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing')); $collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
$collection->add($fixture); foreach ($fixture as $type) {
$collection->add($type);
}
$this->assertSame($expected, $collection->getArrayCopy()); $this->assertSame($expected, $collection->getArrayCopy());
} }
@@ -195,34 +199,34 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
public function provideTypesToExpand($method, $namespace = '\My\Space\\') public function provideTypesToExpand($method, $namespace = '\My\Space\\')
{ {
return array( return array(
array('', array()), array(array(''), array()),
array(' ', array()), array(array(' '), array()),
array('int', array('int')), array(array('int'), array('int')),
array('int ', array('int')), array(array('int '), array('int')),
array('string', array('string')), array(array('string'), array('string')),
array('DocBlock', array($namespace.'DocBlock')), array(array('DocBlock'), array($namespace.'DocBlock')),
array('DocBlock[]', array($namespace.'DocBlock[]')), array(array('DocBlock[]'), array($namespace.'DocBlock[]')),
array(' DocBlock ', array($namespace.'DocBlock')), array(array(' DocBlock '), array($namespace.'DocBlock')),
array('\My\Space\DocBlock', array('\My\Space\DocBlock')), array(array('\My\Space\DocBlock'), array('\My\Space\DocBlock')),
array('Alias\DocBlock', array('\My\Space\Aliasing\DocBlock')), array(array('Alias\DocBlock'), array('\My\Space\Aliasing\DocBlock')),
array( array(
'DocBlock|Tag', array('DocBlock', 'Tag'),
array($namespace .'DocBlock', $namespace .'Tag') array($namespace .'DocBlock', $namespace .'Tag')
), ),
array( array(
'DocBlock|null', array('DocBlock', 'null'),
array($namespace.'DocBlock', 'null') array($namespace.'DocBlock', 'null')
), ),
array( array(
'\My\Space\DocBlock|Tag', array('\My\Space\DocBlock', 'Tag'),
array('\My\Space\DocBlock', $namespace.'Tag') array('\My\Space\DocBlock', $namespace.'Tag')
), ),
array( array(
'DocBlock[]|null', array('DocBlock[]', 'null'),
array($namespace.'DocBlock[]', 'null') array($namespace.'DocBlock[]', 'null')
), ),
array( array(
'DocBlock[]|int[]', array('DocBlock[]', 'int[]'),
array($namespace.'DocBlock[]', 'int[]') array($namespace.'DocBlock[]', 'int[]')
), ),
); );