Skip to content

Commit bb19583

Browse files
committed
Support braces in types for @param
1 parent 506fd89 commit bb19583

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/DocBlock/Tags/Param.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,8 @@
2929
/**
3030
* Reflection class for the {@}param tag in a Docblock.
3131
*/
32-
final class Param extends BaseTag implements Factory\StaticMethod
32+
final class Param extends TagWithType implements Factory\StaticMethod
3333
{
34-
/** @var string */
35-
protected $name = 'param';
36-
37-
/** @var Type|null */
38-
private $type;
39-
4034
/** @var string|null */
4135
private $variableName;
4236

@@ -49,6 +43,7 @@ public function __construct(
4943
bool $isVariadic = false,
5044
?Description $description = null
5145
) {
46+
$this->name = 'param';
5247
$this->variableName = $variableName;
5348
$this->type = $type;
5449
$this->isVariadic = $isVariadic;
@@ -68,21 +63,24 @@ public static function create(
6863
Assert::notNull($typeResolver);
6964
Assert::notNull($descriptionFactory);
7065

71-
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
72-
Assert::isArray($parts);
73-
$type = null;
66+
list($firstPart, $body) = self::extractTypeFromBody($body);
67+
$type = null;
68+
$parts = preg_split('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
7469
$variableName = '';
7570
$isVariadic = false;
7671

7772
// if the first item that is encountered is not a variable; it is a type
78-
if (isset($parts[0]) && ($parts[0] !== '') && ($parts[0][0] !== '$')) {
79-
$type = $typeResolver->resolve(array_shift($parts), $context);
80-
array_shift($parts);
73+
if ($firstPart && (strlen($firstPart) > 0) && ($firstPart[0] !== '$')) {
74+
$type = $typeResolver->resolve($firstPart, $context);
75+
} else {
76+
// first part is not a type; we should prepend it to the parts array for further processing
77+
array_unshift($parts, $firstPart);
8178
}
8279

8380
// if the next item starts with a $ or ...$ it must be the variable name
84-
if (isset($parts[0]) && ($parts[0] !== '') &&
85-
(strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0)
81+
if (isset($parts[0])
82+
&& (strlen($parts[0]) > 0)
83+
&& ($parts[0][0] === '$' || substr($parts[0], 0, 4) === '...$')
8684
) {
8785
$variableName = array_shift($parts);
8886
array_shift($parts);
@@ -110,14 +108,6 @@ public function getVariableName() : ?string
110108
return $this->variableName;
111109
}
112110

113-
/**
114-
* Returns the variable's type or null if unknown.
115-
*/
116-
public function getType() : ?Type
117-
{
118-
return $this->type;
119-
}
120-
121111
/**
122112
* Returns whether this tag is variadic.
123113
*/

0 commit comments

Comments
 (0)