mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-17 17:47:13 +00:00
Generic types bug fix
This commit is contained in:
@@ -26,7 +26,7 @@ class ReturnTag extends Tag
|
||||
{
|
||||
/** @var string The raw type component. */
|
||||
protected $type = '';
|
||||
|
||||
|
||||
/** @var Collection The parsed type component. */
|
||||
protected $types = null;
|
||||
|
||||
@@ -49,7 +49,7 @@ class ReturnTag extends Tag
|
||||
{
|
||||
parent::setContent($content);
|
||||
|
||||
$parts = preg_split('/\s+/Su', $this->description, 2);
|
||||
$parts = preg_split('/(?<!,)\s+/Su', $this->description, 2);
|
||||
|
||||
// any output is considered a type
|
||||
$this->type = $parts[0];
|
||||
@@ -112,7 +112,7 @@ class ReturnTag extends Tag
|
||||
|
||||
/**
|
||||
* Returns the type collection.
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getTypesCollection()
|
||||
|
||||
@@ -106,7 +106,7 @@ class Collection extends \ArrayObject
|
||||
}
|
||||
|
||||
// separate the type by the OR operator
|
||||
$type_parts = explode(self::OPERATOR_OR, $type);
|
||||
$type_parts = $this->explode($type);
|
||||
foreach ($type_parts as $part) {
|
||||
$expanded_type = $this->expand($part);
|
||||
if ($expanded_type) {
|
||||
@@ -114,10 +114,10 @@ class Collection extends \ArrayObject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string representation of the collection.
|
||||
*
|
||||
*
|
||||
* @return string The resolved types across the collection, separated with
|
||||
* {@link self::OPERATOR_OR}.
|
||||
*/
|
||||
@@ -126,6 +126,40 @@ class Collection extends \ArrayObject
|
||||
return implode(self::OPERATOR_OR, $this->getArrayCopy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyzes the given union of types and returns separated by OR operator
|
||||
* single types.
|
||||
*
|
||||
* @param string $type The type or union of types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function explode($type)
|
||||
{
|
||||
$type_parts = [];
|
||||
$curr_type = '';
|
||||
$nest_level = 0;
|
||||
|
||||
foreach (str_split($type) as $char) {
|
||||
if ($char === self::OPERATOR_OR && $nest_level === 0) {
|
||||
$type_parts[] = $curr_type;
|
||||
$curr_type = '';
|
||||
} else {
|
||||
if ($char === '<') {
|
||||
$nest_level++;
|
||||
} else if ($char === '>') {
|
||||
$nest_level--;
|
||||
}
|
||||
|
||||
$curr_type .= $char;
|
||||
}
|
||||
}
|
||||
|
||||
$type_parts[] = $curr_type;
|
||||
|
||||
return $type_parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyzes the given type and returns the FQCN variant.
|
||||
*
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor Return tag test.
|
||||
*
|
||||
*
|
||||
* PHP version 5.3
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
@@ -96,6 +96,27 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase
|
||||
'int',
|
||||
array('int'),
|
||||
"Number of Bobs"
|
||||
),
|
||||
array(
|
||||
'return',
|
||||
'array<int, string> Types of Bobs',
|
||||
'array<int, string>',
|
||||
array('array<int, string>'),
|
||||
'Types of Bobs'
|
||||
),
|
||||
array(
|
||||
'return',
|
||||
'array<int, string>|string Types of Bobs',
|
||||
'array<int, string>|string',
|
||||
array('array<int, string>', 'string'),
|
||||
'Types of Bobs'
|
||||
),
|
||||
array(
|
||||
'return',
|
||||
'array<int, string|bool>|string Types of Bobs',
|
||||
'array<int, string|bool>|string',
|
||||
array('array<int, string|bool>', 'string'),
|
||||
'Types of Bobs'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor Collection Test
|
||||
*
|
||||
*
|
||||
* PHP version 5.3
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
@@ -16,7 +16,7 @@ use Barryvdh\Reflection\DocBlock\Context;
|
||||
|
||||
/**
|
||||
* Test class for \Barryvdh\Reflection\DocBlock\Type\Collection
|
||||
*
|
||||
*
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection
|
||||
*
|
||||
* @author Mike van Riel <[email protected]>
|
||||
@@ -29,7 +29,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::__construct
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::getContext
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstruct()
|
||||
@@ -42,7 +42,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::__construct
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructWithTypes()
|
||||
@@ -53,7 +53,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::__construct
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructWithNamespace()
|
||||
@@ -70,7 +70,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::__construct
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConstructWithNamespaceAliases()
|
||||
@@ -89,7 +89,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @dataProvider provideTypesToExpand
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdd($fixture, $expected)
|
||||
@@ -109,7 +109,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @dataProvider provideTypesToExpandWithoutNamespace
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddWithoutNamespace($fixture, $expected)
|
||||
@@ -146,7 +146,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @covers Barryvdh\Reflection\DocBlock\Type\Collection::add
|
||||
* @expectedException InvalidArgumentException
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddWithInvalidArgument()
|
||||
@@ -197,6 +197,22 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
||||
'DocBlock[]|int[]',
|
||||
array($namespace.'DocBlock[]', 'int[]')
|
||||
),
|
||||
array(
|
||||
'array<int, string>',
|
||||
array('array<int, string>')
|
||||
),
|
||||
array(
|
||||
'array<int, string>|string',
|
||||
array('array<int, string>', 'string')
|
||||
),
|
||||
array(
|
||||
'array<int, float|bool>|string',
|
||||
array('array<int, float|bool>', 'string')
|
||||
),
|
||||
array(
|
||||
'array<int, string|array<int, bool>>|array<int, float>|string',
|
||||
array('array<int, string|array<int, bool>>', 'array<int, float>', 'string')
|
||||
),
|
||||
array(
|
||||
'LinkDescriptor::setLink()',
|
||||
array($namespace.'LinkDescriptor::setLink()')
|
||||
|
||||
Reference in New Issue
Block a user