Skip to content

Commit

Permalink
Merge pull request #1491 from ruudk/doctrine-lexer-v2
Browse files Browse the repository at this point in the history
Require Doctrine Lexer v2 and stop accessing Token properties via ArrayAccess to stop deprecation
  • Loading branch information
goetas authored Jun 9, 2023
2 parents bd18f0a + a9158b1 commit d1384d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": "^7.2||^8.0",
"doctrine/annotations": "^1.13 || ^2.0",
"doctrine/instantiator": "^1.0.3 || ^2.0",
"doctrine/lexer": "^1.1 || ^2",
"doctrine/lexer": "^2",
"jms/metadata": "^2.6",
"phpstan/phpdoc-parser": "^0.4 || ^0.5 || ^1.0"
},
Expand Down
32 changes: 16 additions & 16 deletions src/Type/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,30 @@ private function visit()
);
}

if (Lexer::T_FLOAT === $this->lexer->token['type']) {
return floatval($this->lexer->token['value']);
} elseif (Lexer::T_INTEGER === $this->lexer->token['type']) {
return intval($this->lexer->token['value']);
} elseif (Lexer::T_NULL === $this->lexer->token['type']) {
if (Lexer::T_FLOAT === $this->lexer->token->type) {
return floatval($this->lexer->token->value);
} elseif (Lexer::T_INTEGER === $this->lexer->token->type) {
return intval($this->lexer->token->value);
} elseif (Lexer::T_NULL === $this->lexer->token->type) {
return null;
} elseif (Lexer::T_STRING === $this->lexer->token['type']) {
return $this->lexer->token['value'];
} elseif (Lexer::T_IDENTIFIER === $this->lexer->token['type']) {
} elseif (Lexer::T_STRING === $this->lexer->token->type) {
return $this->lexer->token->value;
} elseif (Lexer::T_IDENTIFIER === $this->lexer->token->type) {
if ($this->lexer->isNextToken(Lexer::T_TYPE_START)) {
return $this->visitCompoundType();
} elseif ($this->lexer->isNextToken(Lexer::T_ARRAY_START)) {
return $this->visitArrayType();
}

return $this->visitSimpleType();
} elseif (!$this->root && Lexer::T_ARRAY_START === $this->lexer->token['type']) {
} elseif (!$this->root && Lexer::T_ARRAY_START === $this->lexer->token->type) {
return $this->visitArrayType();
}

throw new SyntaxError(sprintf(
'Syntax error, unexpected "%s" (%s)',
$this->lexer->token['value'],
$this->getConstant($this->lexer->token['type'])
$this->lexer->token->value,
$this->getConstant($this->lexer->token->type)
));
}

Expand All @@ -75,15 +75,15 @@ private function visit()
*/
private function visitSimpleType()
{
$value = $this->lexer->token['value'];
$value = $this->lexer->token->value;

return ['name' => $value, 'params' => []];
}

private function visitCompoundType(): array
{
$this->root = false;
$name = $this->lexer->token['value'];
$name = $this->lexer->token->value;
$this->match(Lexer::T_TYPE_START);

$params = [];
Expand Down Expand Up @@ -139,16 +139,16 @@ private function match(int $token): void
);
}

if ($this->lexer->lookahead['type'] === $token) {
if ($this->lexer->lookahead->type === $token) {
$this->lexer->moveNext();

return;
}

throw new SyntaxError(sprintf(
'Syntax error, unexpected "%s" (%s), expected was %s',
$this->lexer->lookahead['value'],
$this->getConstant($this->lexer->lookahead['type']),
$this->lexer->lookahead->value,
$this->getConstant($this->lexer->lookahead->type),
$this->getConstant($token)
));
}
Expand Down

0 comments on commit d1384d3

Please sign in to comment.