diff --git a/src/Parser/PhpDocParser.php b/src/Parser/PhpDocParser.php index ff5f18f6..c21358cf 100644 --- a/src/Parser/PhpDocParser.php +++ b/src/Parser/PhpDocParser.php @@ -682,24 +682,34 @@ private function parseDoctrineArgumentValue(TokenIterator $tokens) $tokens->dropSavePoint(); // because of ConstFetchNode } - $exception = new ParserException( - $tokens->currentTokenValue(), - $tokens->currentTokenType(), - $tokens->currentTokenOffset(), - Lexer::TOKEN_IDENTIFIER, - null, - $tokens->currentTokenLine() - ); + $currentTokenValue = $tokens->currentTokenValue(); + $currentTokenType = $tokens->currentTokenType(); + $currentTokenOffset = $tokens->currentTokenOffset(); + $currentTokenLine = $tokens->currentTokenLine(); try { $constExpr = $this->doctrineConstantExprParser->parse($tokens, true); if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) { - throw $exception; + throw new ParserException( + $currentTokenValue, + $currentTokenType, + $currentTokenOffset, + Lexer::TOKEN_IDENTIFIER, + null, + $currentTokenLine + ); } return $constExpr; } catch (LogicException $e) { - throw $exception; + throw new ParserException( + $currentTokenValue, + $currentTokenType, + $currentTokenOffset, + Lexer::TOKEN_IDENTIFIER, + null, + $currentTokenLine + ); } } diff --git a/src/Parser/TypeParser.php b/src/Parser/TypeParser.php index 645f544b..d0b1fdea 100644 --- a/src/Parser/TypeParser.php +++ b/src/Parser/TypeParser.php @@ -196,28 +196,45 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode $tokens->dropSavePoint(); // because of ConstFetchNode } - $exception = new ParserException( - $tokens->currentTokenValue(), - $tokens->currentTokenType(), - $tokens->currentTokenOffset(), - Lexer::TOKEN_IDENTIFIER, - null, - $tokens->currentTokenLine() - ); + $currentTokenValue = $tokens->currentTokenValue(); + $currentTokenType = $tokens->currentTokenType(); + $currentTokenOffset = $tokens->currentTokenOffset(); + $currentTokenLine = $tokens->currentTokenLine(); if ($this->constExprParser === null) { - throw $exception; + throw new ParserException( + $currentTokenValue, + $currentTokenType, + $currentTokenOffset, + Lexer::TOKEN_IDENTIFIER, + null, + $currentTokenLine + ); } try { $constExpr = $this->constExprParser->parse($tokens, true); if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) { - throw $exception; + throw new ParserException( + $currentTokenValue, + $currentTokenType, + $currentTokenOffset, + Lexer::TOKEN_IDENTIFIER, + null, + $currentTokenLine + ); } return $this->enrichWithAttributes($tokens, new Ast\Type\ConstTypeNode($constExpr), $startLine, $startIndex); } catch (LogicException $e) { - throw $exception; + throw new ParserException( + $currentTokenValue, + $currentTokenType, + $currentTokenOffset, + Lexer::TOKEN_IDENTIFIER, + null, + $currentTokenLine + ); } } @@ -600,23 +617,33 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo } } - $exception = new ParserException( - $tokens->currentTokenValue(), - $tokens->currentTokenType(), - $tokens->currentTokenOffset(), - Lexer::TOKEN_IDENTIFIER, - null, - $tokens->currentTokenLine() - ); + $currentTokenValue = $tokens->currentTokenValue(); + $currentTokenType = $tokens->currentTokenType(); + $currentTokenOffset = $tokens->currentTokenOffset(); + $currentTokenLine = $tokens->currentTokenLine(); if ($this->constExprParser === null) { - throw $exception; + throw new ParserException( + $currentTokenValue, + $currentTokenType, + $currentTokenOffset, + Lexer::TOKEN_IDENTIFIER, + null, + $currentTokenLine + ); } try { $constExpr = $this->constExprParser->parse($tokens, true); if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) { - throw $exception; + throw new ParserException( + $currentTokenValue, + $currentTokenType, + $currentTokenOffset, + Lexer::TOKEN_IDENTIFIER, + null, + $currentTokenLine + ); } $type = new Ast\Type\ConstTypeNode($constExpr); @@ -631,7 +658,14 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo return $type; } catch (LogicException $e) { - throw $exception; + throw new ParserException( + $currentTokenValue, + $currentTokenType, + $currentTokenOffset, + Lexer::TOKEN_IDENTIFIER, + null, + $currentTokenLine + ); } }