8000 Add doctrine/lexer v3 compatibility by zanardigit · Pull Request #3527 · bolt/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add doctrine/lexer v3 compatibility #3527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Doctrine/Query/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
$this->first = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_AS);
$parser->match(Lexer::T_IDENTIFIER);
$this->second = $parser->getLexer()->token['value'];
$this->second = $parser->getLexer()->token->value;

Check failure on line 55 in src/Doctrine/Query/Cast.php

View workflow job for this annotation

GitHub Actions / PHPStan

Cannot access property $value on array<string, int|string|null>.

Check failure on line 55 in src/Doctrine/Query/Cast.php

View workflow job for this annotation

GitHub Actions / PHPStan

Cannot access property $value on array<string, int|string|null>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bobvandevijver I have written this code to fix it because the Lexer can be installed in version 2 or 3!

Suggested change
$this->second = $parser->getLexer()->token->value;
// doctrine/lexer v2
if (is_array($parser->getLexer()->token)) {
$this->second = $parser->getLexer()->token['value'];
/** @phpstan-ignore-next-line */
} elseif (is_object($parser->getLexer()->token)) { // doctrine/lexer v3
$this->second = $parser->getLexer()->token->value;
} else {
throw new \LogicException('Unable to access parser token');
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macintoshplus it's been a while since I tested this, but as far as i remember using the token as a Token object should be compatible with both v2 and v3 of doctrine/lexer. So, that is probably not required. Feel free to correct me if you found different results.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zanardigit, I have fixed this error today by requiring doctrine/lexer v2 in my project.
After the library downgrade the Bolt code works fine but, I don't want to keep this requirement in my project.

We don't know the version used in the project. We must assume works with version 2 or 3.

Copy link
Author
@zanardigit zanardigit Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macintoshplus cannot test right now, I trust you.
In that case, my PR should be rejected; you should issue a new one with the proposed changes, which are safer and will work in any case, so they are definitely better.

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
Loading
0