mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Merge pull request #9 from bbprojectnet/generic-types-fix
Generic types recognitions bug fix
This commit is contained in:
@@ -49,7 +49,7 @@ class ReturnTag extends Tag
|
|||||||
{
|
{
|
||||||
parent::setContent($content);
|
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
|
// any output is considered a type
|
||||||
$this->type = $parts[0];
|
$this->type = $parts[0];
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class Collection extends \ArrayObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// separate the type by the OR operator
|
// separate the type by the OR operator
|
||||||
$type_parts = explode(self::OPERATOR_OR, $type);
|
$type_parts = $this->explode($type);
|
||||||
foreach ($type_parts as $part) {
|
foreach ($type_parts as $part) {
|
||||||
$expanded_type = $this->expand($part);
|
$expanded_type = $this->expand($part);
|
||||||
if ($expanded_type) {
|
if ($expanded_type) {
|
||||||
@@ -126,6 +126,40 @@ class Collection extends \ArrayObject
|
|||||||
return implode(self::OPERATOR_OR, $this->getArrayCopy());
|
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.
|
* Analyzes the given type and returns the FQCN variant.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -96,6 +96,27 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase
|
|||||||
'int',
|
'int',
|
||||||
array('int'),
|
array('int'),
|
||||||
"Number of Bobs"
|
"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'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,22 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
|
|||||||
'DocBlock[]|int[]',
|
'DocBlock[]|int[]',
|
||||||
array($namespace.'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(
|
array(
|
||||||
'LinkDescriptor::setLink()',
|
'LinkDescriptor::setLink()',
|
||||||
array($namespace.'LinkDescriptor::setLink()')
|
array($namespace.'LinkDescriptor::setLink()')
|
||||||
|
|||||||
Reference in New Issue
Block a user