|
8 | 8 | class PhpDocParser
|
9 | 9 | {
|
10 | 10 |
|
| 11 | + const DISALLOWED_DESCRIPTION_START_TOKENS = [ |
| 12 | + Lexer::TOKEN_UNION, |
| 13 | + Lexer::TOKEN_INTERSECTION, |
| 14 | + Lexer::TOKEN_OPEN_ANGLE_BRACKET, |
| 15 | + ]; |
| 16 | + |
11 | 17 | /** @var TypeParser */
|
12 | 18 | private $typeParser;
|
13 | 19 |
|
@@ -116,24 +122,24 @@ private function parseParamTagValue(TokenIterator $tokens): Ast\PhpDoc\ParamTagV
|
116 | 122 | {
|
117 | 123 | $type = $this->typeParser->parse($tokens);
|
118 | 124 | $parameterName = $this->parseOptionalVariableName($tokens);
|
119 |
| - $description = $this->parseOptionalDescription($tokens); |
| 125 | + $description = $this->parseOptionalDescription($tokens, $parameterName === ''); |
120 | 126 | return new Ast\PhpDoc\ParamTagValueNode($type, $parameterName, $description);
|
121 | 127 | }
|
122 | 128 |
|
123 | 129 |
|
124 | 130 | private function parseVarTagValue(TokenIterator $tokens): Ast\PhpDoc\VarTagValueNode
|
125 | 131 | {
|
126 | 132 | $type = $this->typeParser->parse($tokens);
|
127 |
| - $parameterName = $this->parseOptionalVariableName($tokens); |
128 |
| - $description = $this->parseOptionalDescription($tokens); |
129 |
| - return new Ast\PhpDoc\VarTagValueNode($type, $parameterName, $description); |
| 133 | + $variableName = $this->parseOptionalVariableName($tokens); |
| 134 | + $description = $this->parseOptionalDescription($tokens, $variableName === ''); |
| 135 | + return new Ast\PhpDoc\VarTagValueNode($type, $variableName, $description); |
130 | 136 | }
|
131 | 137 |
|
132 | 138 |
|
133 | 139 | private function parseReturnTagValue(TokenIterator $tokens): Ast\PhpDoc\ReturnTagValueNode
|
134 | 140 | {
|
135 | 141 | $type = $this->typeParser->parse($tokens);
|
136 |
| - $description = $this->parseOptionalDescription($tokens); |
| 142 | + $description = $this->parseOptionalDescription($tokens, true); |
137 | 143 | return new Ast\PhpDoc\ReturnTagValueNode($type, $description);
|
138 | 144 | }
|
139 | 145 |
|
@@ -235,8 +241,16 @@ private function parseRequiredVariableName(TokenIterator $tokens): string
|
235 | 241 | }
|
236 | 242 |
|
237 | 243 |
|
238 |
| - private function parseOptionalDescription(TokenIterator $tokens): string |
| 244 | + private function parseOptionalDescription(TokenIterator $tokens, bool $limitStartToken = false): string |
239 | 245 | {
|
| 246 | + if ($limitStartToken) { |
| 247 | + foreach (self::DISALLOWED_DESCRIPTION_START_TOKENS as $disallowedStartToken) { |
| 248 | + if ($tokens->isCurrentTokenType($disallowedStartToken)) { |
| 249 | + $tokens->consumeTokenType(Lexer::TOKEN_OTHER); // will throw exception |
| 250 | + } |
| 251 | + } |
| 252 | + } |
| 253 | + |
240 | 254 | // description MUST separated from any previous node by horizontal whitespace
|
241 | 255 | if ($tokens->tryConsumeHorizontalWhiteSpace()) {
|
242 | 256 | return $tokens->joinUntil(Lexer::TOKEN_EOL, Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_CLOSE_PHPDOC);
|
|
0 commit comments