Skip to content

Commit db20ae3

Browse files
committed
Moved the type separation into ReturnTag, for consistency with the type merging that is currently there.
1 parent cdaa97e commit db20ae3

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct($type, $content, DocBlock $docblock = null)
5353
public function getTypes()
5454
{
5555
$types = new \phpDocumentor\Reflection\DocBlock\Type\Collection(
56-
array($this->type),
56+
explode('|', $this->type),
5757
$this->docblock ? $this->docblock->getNamespace() : null,
5858
$this->docblock ? $this->docblock->getNamespaceAliases() : array()
5959
);

src/phpDocumentor/Reflection/DocBlock/Type/Collection.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
*/
2323
class Collection extends \ArrayObject
2424
{
25-
/** @var string Definition of the OR operator for types */
26-
const OPERATOR_OR = '|';
27-
2825
/** @var string Definition of the ARRAY operator for types */
2926
const OPERATOR_ARRAY = '[]';
3027

@@ -167,14 +164,9 @@ public function add($type)
167164
.var_export($type, true)
168165
);
169166
}
170-
171-
// separate the type by the OR operator
172-
$type_parts = explode(self::OPERATOR_OR, $type);
173-
foreach ($type_parts as $part) {
174-
$expanded_type = $this->expand($part);
175-
if ($expanded_type) {
176-
$this[] = $expanded_type;
177-
}
167+
$expanded_type = $this->expand($type);
168+
if ($expanded_type) {
169+
$this[] = $expanded_type;
178170
}
179171
}
180172

tests/phpDocumentor/Reflection/DocBlock/Type/CollectionTest.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ public function testAdd($fixture, $expected)
148148
$collection = new Collection();
149149
$collection->setNamespace('\My\Space');
150150
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
151-
$collection->add($fixture);
151+
foreach ($fixture as $type) {
152+
$collection->add($type);
153+
}
152154

153155
$this->assertSame($expected, $collection->getArrayCopy());
154156
}
@@ -166,7 +168,9 @@ public function testAddWithoutNamespace($fixture, $expected)
166168
{
167169
$collection = new Collection();
168170
$collection->setNamespaceAliases(array('Alias' => '\My\Space\Aliasing'));
169-
$collection->add($fixture);
171+
foreach ($fixture as $type) {
172+
$collection->add($type);
173+
}
170174

171175
$this->assertSame($expected, $collection->getArrayCopy());
172176
}
@@ -195,34 +199,34 @@ public function testAddWithInvalidArgument()
195199
public function provideTypesToExpand($method, $namespace = '\My\Space\\')
196200
{
197201
return array(
198-
array('', array()),
199-
array(' ', array()),
200-
array('int', array('int')),
201-
array('int ', array('int')),
202-
array('string', array('string')),
203-
array('DocBlock', array($namespace.'DocBlock')),
204-
array('DocBlock[]', array($namespace.'DocBlock[]')),
205-
array(' DocBlock ', array($namespace.'DocBlock')),
206-
array('\My\Space\DocBlock', array('\My\Space\DocBlock')),
207-
array('Alias\DocBlock', array('\My\Space\Aliasing\DocBlock')),
202+
array(array(''), array()),
203+
array(array(' '), array()),
204+
array(array('int'), array('int')),
205+
array(array('int '), array('int')),
206+
array(array('string'), array('string')),
207+
array(array('DocBlock'), array($namespace.'DocBlock')),
208+
array(array('DocBlock[]'), array($namespace.'DocBlock[]')),
209+
array(array(' DocBlock '), array($namespace.'DocBlock')),
210+
array(array('\My\Space\DocBlock'), array('\My\Space\DocBlock')),
211+
array(array('Alias\DocBlock'), array('\My\Space\Aliasing\DocBlock')),
208212
array(
209-
'DocBlock|Tag',
213+
array('DocBlock', 'Tag'),
210214
array($namespace .'DocBlock', $namespace .'Tag')
211215
),
212216
array(
213-
'DocBlock|null',
217+
array('DocBlock', 'null'),
214218
array($namespace.'DocBlock', 'null')
215219
),
216220
array(
217-
'\My\Space\DocBlock|Tag',
221+
array('\My\Space\DocBlock', 'Tag'),
218222
array('\My\Space\DocBlock', $namespace.'Tag')
219223
),
220224
array(
221-
'DocBlock[]|null',
225+
array('DocBlock[]', 'null'),
222226
array($namespace.'DocBlock[]', 'null')
223227
),
224228
array(
225-
'DocBlock[]|int[]',
229+
array('DocBlock[]', 'int[]'),
226230
array($namespace.'DocBlock[]', 'int[]')
227231
),
228232
);

0 commit comments

Comments
 (0)