Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit da5bd4a

Browse files
Avoid creating an Exception when it is not necessary.
1 parent 846ae76 commit da5bd4a

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

‎src/Parser/TypeParser.php‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,28 +196,45 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
196196
$tokens->dropSavePoint(); // because of ConstFetchNode
197197
}
198198

199-
$exception = new ParserException(
200-
$tokens->currentTokenValue(),
201-
$tokens->currentTokenType(),
202-
$tokens->currentTokenOffset(),
203-
Lexer::TOKEN_IDENTIFIER,
204-
null,
205-
$tokens->currentTokenLine()
206-
);
199+
$currentTokenValue = $tokens->currentTokenValue();
200+
$currentTokenType = $tokens->currentTokenType();
201+
$currentTokenOffset = $tokens->currentTokenOffset();
202+
$currentTokenLine = $tokens->currentTokenLine();
207203

208204
if ($this->constExprParser === null) {
209-
throw $exception;
205+
throw new ParserException(
206+
$currentTokenValue,
207+
$currentTokenType,
208+
$currentTokenOffset,
209+
Lexer::TOKEN_IDENTIFIER,
210+
null,
211+
$currentTokenLine
212+
);
210213
}
211214

212215
try {
213216
$constExpr = $this->constExprParser->parse($tokens, true);
214217
if ($constExpr instanceof Ast\ConstExpr\ConstExprArrayNode) {
215-
throw $exception;
218+
throw new ParserException(
219+
$currentTokenValue,
220+
$currentTokenType,
221+
$currentTokenOffset,
222+
Lexer::TOKEN_IDENTIFIER,
223+
null,
224+
$currentTokenLine
225+
);
216226
}
217227

218228
return $this->enrichWithAttributes($tokens, new Ast\Type\ConstTypeNode($constExpr), $startLine, $startIndex);
219229
} catch (LogicException $e) {
220-
throw $exception;
230+
throw new ParserException(
231+
$currentTokenValue,
232+
$currentTokenType,
233+
$currentTokenOffset,
234+
Lexer::TOKEN_IDENTIFIER,
235+
null,
236+
$currentTokenLine
237+
);
221238
}
222239
}
223240

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /