From 2e6cecb9ef7a47b2c58b97f20c3b60be3b5f61c4 Mon Sep 17 00:00:00 2001 From: Lars Moelleken Date: Tue, 1 Sep 2020 17:52:33 +0200 Subject: [PATCH] Param: do not resolve types if it's not possible -> https://travis-ci.org/github/JetBrains/phpstorm-stubs/builds/723069982 -> https://github.com/JetBrains/phpstorm-stubs/pull/892 --- src/DocBlock/Tags/Param.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 392b4f9..dea81a7 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -75,7 +75,7 @@ final class Param extends TagWithType implements Factory\StaticMethod $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 @@ -83,18 +83,7 @@ final class Param extends TagWithType implements Factory\StaticMethod } // 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); @@ -155,4 +144,20 @@ final class Param extends TagWithType implements Factory\StaticMethod . ($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; + } }