function PhpDocParser::parseDoctrineArrayKey
*
Return value
ConstExprIntegerNode|ConstExprStringNode|IdentifierTypeNode|ConstFetchNode
1 call to PhpDocParser::parseDoctrineArrayKey()
- PhpDocParser::parseDoctrineArrayItem in vendor/
phpstan/ phpdoc-parser/ src/ Parser/ PhpDocParser.php
File
-
vendor/
phpstan/ phpdoc-parser/ src/ Parser/ PhpDocParser.php, line 809
Class
- PhpDocParser
- @phpstan-import-type ValueType from Doctrine\DoctrineArgument as DoctrineValueType
Namespace
PHPStan\PhpDocParser\ParserCode
private function parseDoctrineArrayKey(TokenIterator $tokens) {
$startLine = $tokens->currentTokenLine();
$startIndex = $tokens->currentTokenIndex();
if ($tokens->isCurrentTokenType(Lexer::TOKEN_INTEGER)) {
$key = new Ast\ConstExpr\ConstExprIntegerNode(str_replace('_', '', $tokens->currentTokenValue()));
$tokens->next();
}
elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_DOCTRINE_ANNOTATION_STRING)) {
$key = new Ast\ConstExpr\DoctrineConstExprStringNode(Ast\ConstExpr\DoctrineConstExprStringNode::unescape($tokens->currentTokenValue()));
$tokens->next();
}
elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_DOUBLE_QUOTED_STRING)) {
$value = $tokens->currentTokenValue();
$tokens->next();
$key = $this->doctrineConstantExprParser
->parseDoctrineString($value, $tokens);
}
else {
$currentTokenValue = $tokens->currentTokenValue();
$tokens->pushSavePoint();
// because of ConstFetchNode
if (!$tokens->tryConsumeTokenType(Lexer::TOKEN_IDENTIFIER)) {
$tokens->dropSavePoint();
throw new ParserException($tokens->currentTokenValue(), $tokens->currentTokenType(), $tokens->currentTokenOffset(), Lexer::TOKEN_IDENTIFIER, null, $tokens->currentTokenLine());
}
if (!$tokens->isCurrentTokenType(Lexer::TOKEN_DOUBLE_COLON)) {
$tokens->dropSavePoint();
return $this->enrichWithAttributes($tokens, new IdentifierTypeNode($currentTokenValue), $startLine, $startIndex);
}
$tokens->rollback();
$constExpr = $this->doctrineConstantExprParser
->parse($tokens, true);
if (!$constExpr instanceof Ast\ConstExpr\ConstFetchNode) {
throw new ParserException($tokens->currentTokenValue(), $tokens->currentTokenType(), $tokens->currentTokenOffset(), Lexer::TOKEN_IDENTIFIER, null, $tokens->currentTokenLine());
}
return $constExpr;
}
return $this->enrichWithAttributes($tokens, $key, $startLine, $startIndex);
}