Detect unused static method call on a separate line with possibly pure method#3023
Detect unused static method call on a separate line with possibly pure method#3023ondrejmirtes merged 5 commits intophpstan:1.11.xfrom
Conversation
| X::impureFunc(); | ||
| X::callingImpureFunc(); | ||
|
|
||
| $a = X::myFunc(); |
There was a problem hiding this comment.
I did not yet find a way to make the rule error on this Expr. the current PossiblyPureStaticCallCollector is based on Expression which this line is not.
Should I implement a separate Collector for Expr?
There was a problem hiding this comment.
Why do you think this line should error?
There was a problem hiding this comment.
I thought it should, because we do a similar error for functions: 57b0ae0
There was a problem hiding this comment.
Nope, that was a fix so that this is NOT reported.
src/Rules/DeadCode/CallToStaticMethodStatementWithoutImpurePointsRule.php
Outdated
Show resolved
Hide resolved
|
Also - the rules are not registered in config |
|
This pull request has been marked as ready for review. |
|
|
||
| $methodName = $node->expr->name->toString(); | ||
| $calledOnType = $scope->resolveTypeByName($node->expr->class); | ||
| $methodReflection = $scope->getMethodReflection($calledOnType, $methodName); |
There was a problem hiding this comment.
We don't need to go through the type system at all. We have a class name and a method name as strings at hand, so we should go through ReflectionProvider and ClassReflection::getNativeMethod() instead. Thanks.
There was a problem hiding this comment.
Oh scratch that, this actually avoids some other problems.
|
Thank you! |
similar to 281a87d