mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
@@ -38,17 +38,22 @@ final class Param extends TagWithType implements Factory\StaticMethod
|
||||
/** @var bool determines whether this is a variadic argument */
|
||||
private $isVariadic;
|
||||
|
||||
/** @var bool determines whether this is passed by reference */
|
||||
private $isReference;
|
||||
|
||||
public function __construct(
|
||||
?string $variableName,
|
||||
?Type $type = null,
|
||||
bool $isVariadic = false,
|
||||
?Description $description = null
|
||||
?Description $description = null,
|
||||
bool $isReference = false
|
||||
) {
|
||||
$this->name = 'param';
|
||||
$this->variableName = $variableName;
|
||||
$this->type = $type;
|
||||
$this->isVariadic = $isVariadic;
|
||||
$this->description = $description;
|
||||
$this->isReference = $isReference;
|
||||
}
|
||||
|
||||
public static function create(
|
||||
@@ -67,6 +72,7 @@ final class Param extends TagWithType implements Factory\StaticMethod
|
||||
$parts = Utils::pregSplit('/(\s+)/Su', $body, 2, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$variableName = '';
|
||||
$isVariadic = false;
|
||||
$isReference = false;
|
||||
|
||||
// if the first item that is encountered is not a variable; it is a type
|
||||
if ($firstPart && $firstPart[0] !== '$') {
|
||||
@@ -76,26 +82,43 @@ final class Param extends TagWithType implements Factory\StaticMethod
|
||||
array_unshift($parts, $firstPart);
|
||||
}
|
||||
|
||||
// if the next item starts with a $ or ...$ it must be the variable name
|
||||
if (isset($parts[0]) && (strpos($parts[0], '$') === 0 || strpos($parts[0], '...$') === 0)) {
|
||||
// if the next item starts with a $ or ...$ or &$ or &...$ it must be the variable name
|
||||
if (
|
||||
isset($parts[0])
|
||||
&&
|
||||
(
|
||||
strpos($parts[0], '$') === 0
|
||||
||
|
||||
strpos($parts[0], '...$') === 0
|
||||
||
|
||||
strpos($parts[0], '&$') === 0
|
||||
||
|
||||
strpos($parts[0], '&...$') === 0
|
||||
)
|
||||
) {
|
||||
$variableName = array_shift($parts);
|
||||
array_shift($parts);
|
||||
|
||||
Assert::notNull($variableName);
|
||||
|
||||
if (strpos($variableName, '...') === 0) {
|
||||
$isVariadic = true;
|
||||
$variableName = substr($variableName, 3);
|
||||
}
|
||||
|
||||
if (strpos($variableName, '$') === 0) {
|
||||
$variableName = substr($variableName, 1);
|
||||
} elseif(strpos($variableName, '&$') === 0) {
|
||||
$isReference = true;
|
||||
$variableName = substr($variableName, 2);
|
||||
} elseif (strpos($variableName, '...$') === 0) {
|
||||
$isVariadic = true;
|
||||
$variableName = substr($variableName, 4);
|
||||
} elseif (strpos($variableName, '&...$') === 0) {
|
||||
$isVariadic = true;
|
||||
$isReference = true;
|
||||
$variableName = substr($variableName, 5);
|
||||
}
|
||||
}
|
||||
|
||||
$description = $descriptionFactory->create(implode('', $parts), $context);
|
||||
|
||||
return new static($variableName, $type, $isVariadic, $description);
|
||||
return new static($variableName, $type, $isVariadic, $description, $isReference);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,12 +137,21 @@ final class Param extends TagWithType implements Factory\StaticMethod
|
||||
return $this->isVariadic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this tag is passed by reference.
|
||||
*/
|
||||
public function isReference() : bool
|
||||
{
|
||||
return $this->isReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation for this tag.
|
||||
*/
|
||||
public function __toString() : string
|
||||
{
|
||||
return ($this->type ? $this->type . ' ' : '')
|
||||
. ($this->isReference() ? '&' : '')
|
||||
. ($this->isVariadic() ? '...' : '')
|
||||
. ($this->variableName !== null ? '$' . $this->variableName : '')
|
||||
. ($this->description ? ' ' . $this->description : '');
|
||||
|
||||
Reference in New Issue
Block a user