-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
concat without assigment #10389
Comments
I'd do this as rule for BinaryOp using its attribute parent, but this attribute is no longer available. What is current best practice? |
I found |
At least thats what I had in mind on how to implement it. Create a new visitor and store in attributes what is required to make the rule work |
I've implemented it this way, please check phpstan/phpstan-src#2858 |
One way to look at this feature request is that it needs to be implemented in NoopRule where similar nodes are handled. And it would lead to simple code like So it can definitely be added there in NoopRule. But the underlying issue is much more complex. When you consider And at that point this feature request should be implemented as well: #4426 (reporting that This needs to be done in NodeScopeResolver and be decided for all expressions and statements. ExpressionResult and StatementResult need to get a new method describing whether they are pure or not. Last time this was done was with "throw points". If you Ctrl+F in NodeScopeResolver for I'd appreciate if someone tackled this, in small steps. |
I see it is not that simple I thought. NodeScopeResolver is out of my knowledge :) |
Done as part of bleeding edge thanks to impure points: phpstan/phpstan-src@a647052 Please note that functions/methods need |
@ondrejmirtes nice, thank you. one note: I wonder why line 10 did not error: all other lines look great |
Because it might throw DivisionByZeroError. So it's not really "side effect-free" if you want to perform it in order to throw an exception. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Feature request
today I stumbled over a bug, in which someone missed to
echo
the result of a string-concatenation, effectively producing a useless concatenation.would be great if phpstan could error about the concat beeing useless:
https://phpstan.org/r/b76066d6-5fb9-440b-a1f2-16651b6a062d
same could be true for other operations when no assignment is done
https://phpstan.org/r/ae8ba301-436a-4945-aa39-181d7536620c
Did PHPStan help you today? Did it make you happy in any way?
No response
The text was updated successfully, but these errors were encountered: