Skip to content

Commit

Permalink
Param: do not resolve types if it's not possible
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Sep 1, 2020
1 parent 13d9a6b commit 2e6cecb
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/DocBlock/Tags/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,15 @@ public static function create(
$isReference = false;

// if the first item that is encountered is not a variable; it is a type
if ($firstPart && $firstPart[0] !== '$') {
if ($firstPart && !self::strStartsWithVariable($firstPart)) {
$type = $typeResolver->resolve($firstPart, $context);
} else {
// first part is not a type; we should prepend it to the parts array for further processing
array_unshift($parts, $firstPart);
}

// 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
)
) {
if (isset($parts[0]) && self::strStartsWithVariable($parts[0])) {
$variableName = array_shift($parts);
array_shift($parts);

Expand Down Expand Up @@ -155,4 +144,20 @@ public function __toString() : string
. ($this->variableName !== null ? '$' . $this->variableName : '')
. ($this->description ? ' ' . $this->description : '');
}

/**
* @param string $str
*
* @return bool
*/
private static function strStartsWithVariable(string $str): bool
{
return strpos($str, '$') === 0
||
strpos($str, '...$') === 0
||
strpos($str, '&$') === 0
||
strpos($str, '&...$') === 0;
}
}

0 comments on commit 2e6cecb

Please sign in to comment.