From 0bca477a34baea39add016af90046f002a175619 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Fri, 28 Mar 2014 10:21:30 +0100 Subject: [PATCH] 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. --- .../Reflection/DocBlock/Tag/ParamTag.php | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php index f544a9b..9bc0270 100644 --- a/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php +++ b/src/phpDocumentor/Reflection/DocBlock/Tag/ParamTag.php @@ -23,11 +23,12 @@ use phpDocumentor\Reflection\DocBlock\Tag; */ class ParamTag extends ReturnTag { - /** - * @var string - */ + /** @var string */ protected $variableName = ''; + /** @var bool determines whether this is a variadic argument */ + protected $isVariadic = false; + /** * {@inheritdoc} */ @@ -61,13 +62,18 @@ class ParamTag extends ReturnTag 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]) && (strlen($parts[0]) > 0) - && ($parts[0][0] == '$') + && ($parts[0][0] == '$' || substr($parts[0], 0, 4) === '...$') ) { $this->variableName = 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)); @@ -100,4 +106,14 @@ class ParamTag extends ReturnTag $this->content = null; return $this; } + + /** + * Returns whether this tag is variadic. + * + * @return boolean + */ + public function isVariadic() + { + return $this->isVariadic; + } }