Fix phpstan/phpstan#8744: Fix deprecated string interpolation syntax#5038
Fix phpstan/phpstan#8744: Fix deprecated string interpolation syntax#5038codebymikey wants to merge 2 commits intophpstan:2.1.xfrom
Conversation
|
You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x. |
|
I'm not fan of this approach of polluting all the APIs with parser tokens. |
3e82644 to
1741462
Compare
| } | ||
|
|
||
| return [ | ||
| RuleErrorBuilder::message($deprecatedMessage) |
There was a problem hiding this comment.
If it's a deprecation, and not a real error, should it be in deprecation-rules instead ?
There was a problem hiding this comment.
Potentially, my finding was that the rule needs access to the parser tokens in some form to check the original syntax.
So as long as that API is exposed in the main phpstan library, then the rule could be moved into deprecation-rules if that's the most sensible part for it.
Wasn't sure of a better way to expose the tokens received by the parser since the parser interface is currently pretty simple. And tokens are the only way I can think of to address it (that's how Rector fixes it too) Having access to the token as additional context seems like a general improvement for rules that might need it in the future. Any thoughts on how to work around it without the API pollution? Unless only specific parsers have to implement a new |
1741462 to
7c454ec
Compare
7c454ec to
f059229
Compare
| return []; | ||
| } | ||
|
|
||
| $sourceTokens = $scope->getTokens(); |
There was a problem hiding this comment.
could we instead add a new NodeVisitor which inspects the tokens at Ast-Parsing time and add necessary attributes onto the InterpolatedString-node, so we can just work on e.g. $interpolatedString->getAttribute(...) at rule level?
see other visitors in src/Parser which do similar things
There was a problem hiding this comment.
That's a good idea, but I believe we only have access to the same Node object in the AST as we do in the custom rules.
edit: I see what you mean.
4b168f5 to
04d83e1
Compare
04d83e1 to
4f209d6
Compare
Adds support for flagging deprecated string interpolation syntaxes, as well as fixing them.
It involves fetching the token from the parser, and using that to infer the original syntax used in the source code.
Fixes phpstan/phpstan#8744