Implement support for Variadic arguments

Fixes https://github.com/phpDocumentor/phpDocumentor2/issues/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.
This commit is contained in:
Mike van Riel
2014-03-28 10:21:30 +01:00
parent cfb3ebea55
commit 0bca477a34
@@ -23,11 +23,12 @@ use phpDocumentor\Reflection\DocBlock\Tag;
*/ */
class ParamTag extends ReturnTag class ParamTag extends ReturnTag
{ {
/** /** @var string */
* @var string
*/
protected $variableName = ''; protected $variableName = '';
/** @var bool determines whether this is a variadic argument */
protected $isVariadic = false;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@@ -61,13 +62,18 @@ class ParamTag extends ReturnTag
array_shift($parts); array_shift($parts);
} }
// if the next item starts with a $ it must be the variable name // if the next item starts with a $ or ...$ it must be the variable name
if (isset($parts[0]) if (isset($parts[0])
&& (strlen($parts[0]) > 0) && (strlen($parts[0]) > 0)
&& ($parts[0][0] == '$') && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$')
) { ) {
$this->variableName = array_shift($parts); $this->variableName = array_shift($parts);
array_shift($parts); array_shift($parts);
if (substr($this->variableName, 0, 3) === '...') {
$this->isVariadic = true;
$this->variableName = substr($this->variableName, 3);
}
} }
$this->setDescription(implode('', $parts)); $this->setDescription(implode('', $parts));
@@ -100,4 +106,14 @@ class ParamTag extends ReturnTag
$this->content = null; $this->content = null;
return $this; return $this;
} }
/**
* Returns whether this tag is variadic.
*
* @return boolean
*/
public function isVariadic()
{
return $this->isVariadic;
}
} }