Skip to content

Commit 0bca477

Browse files
committed
Implement support for Variadic arguments
Fixes phpDocumentor/phpDocumentor#629, in this commit we add support for recognizing and displaying variadic arguments as described in the Variadics RFC on Internals (https://wiki.php.net/rfc/variadics). This adds support for describing Variadics even before PHP 5.6, where this feature is planned.
1 parent cfb3ebe commit 0bca477

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
*/
2424
class ParamTag extends ReturnTag
2525
{
26-
/**
27-
* @var string
28-
*/
26+
/** @var string */
2927
protected $variableName = '';
3028

29+
/** @var bool determines whether this is a variadic argument */
30+
protected $isVariadic = false;
31+
3132
/**
3233
* {@inheritdoc}
3334
*/
@@ -61,13 +62,18 @@ public function setContent($content)
6162
array_shift($parts);
6263
}
6364

64-
// if the next item starts with a $ it must be the variable name
65+
// if the next item starts with a $ or ...$ it must be the variable name
6566
if (isset($parts[0])
6667
&& (strlen($parts[0]) > 0)
67-
&& ($parts[0][0] == '$')
68+
&& ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')
6869
) {
6970
$this->variableName = array_shift($parts);
7071
array_shift($parts);
72+
73+
if (substr($this->variableName, 0, 3) === '...') {
74+
$this->isVariadic = true;
75+
$this->variableName = substr($this->variableName, 3);
76+
}
7177
}
7278

7379
$this->setDescription(implode('', $parts));
@@ -100,4 +106,14 @@ public function setVariableName($name)
100106
$this->content = null;
101107
return $this;
102108
}
109+
110+
/**
111+
* Returns whether this tag is variadic.
112+
*
113+
* @return boolean
114+
*/
115+
public function isVariadic()
116+
{
117+
return $this->isVariadic;
118+
}
103119
}

0 commit comments

Comments
 (0)