mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Fixed parsing of string literals and array shapes (#27)
This commit is contained in:
@@ -54,16 +54,15 @@ class ParamTag extends ReturnTag
|
||||
for($pos = 0, $stacks = []; $pos < strlen($rest); $pos++) {
|
||||
$char = $rest[$pos];
|
||||
|
||||
if($char === '<') {
|
||||
if(in_array($char, ['<', '(', '[', '{'])) {
|
||||
array_unshift($stacks, $char);
|
||||
}
|
||||
if($char === '(') {
|
||||
array_unshift($stacks, $char);
|
||||
}
|
||||
if($char === '>' && isset($stacks[0]) && $stacks[0] === '<') {
|
||||
array_shift($stacks);
|
||||
}
|
||||
if($char === ')' && isset($stacks[0]) && $stacks[0] === '(') {
|
||||
if(
|
||||
($char === '>' && isset($stacks[0]) && $stacks[0] === '<')
|
||||
|| ($char === ')' && isset($stacks[0]) && $stacks[0] === '(')
|
||||
|| ($char === ']' && isset($stacks[0]) && $stacks[0] === '[')
|
||||
|| ($char === '}' && isset($stacks[0]) && $stacks[0] === '{')
|
||||
) {
|
||||
array_shift($stacks);
|
||||
}
|
||||
|
||||
|
||||
@@ -161,9 +161,9 @@ class Collection extends \ArrayObject
|
||||
$type_parts[] = $curr_type;
|
||||
$curr_type = '';
|
||||
} else {
|
||||
if ($char === '<' || $char === '(') {
|
||||
if (in_array($char, ['<', '(', '[', '{'])) {
|
||||
$nest_level++;
|
||||
} else if ($char === '>' || $char === ')') {
|
||||
} else if (in_array($char, ['>', ')', ']', '}'])) {
|
||||
$nest_level--;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,8 @@ class Collection extends \ArrayObject
|
||||
return '';
|
||||
}
|
||||
|
||||
if (preg_match('/^[\w-]+<.*>$/', $type)) {
|
||||
// Check for generics values and array shapes
|
||||
if (preg_match('/^[\w-]+(<.+>|\[.+\]|{.+})$/', $type)) {
|
||||
return $type;
|
||||
}
|
||||
|
||||
@@ -214,6 +215,11 @@ class Collection extends \ArrayObject
|
||||
return $type;
|
||||
}
|
||||
|
||||
// Literal strings
|
||||
if ($type[0] === '"' || $type[0] === "'") {
|
||||
return $type;
|
||||
}
|
||||
|
||||
if ($this->isTypeAnArray($type)) {
|
||||
return $this->expand(substr($type, 0, -2)) . self::OPERATOR_ARRAY;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user