-
Notifications
You must be signed in to change notification settings - Fork 504
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
Detect unused static method call on a separate line with possibly pure method #3023
Conversation
…e method
X::impureFunc(); | ||
X::callingImpureFunc(); | ||
|
||
$a = X::myFunc(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you think this line should error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it should, because we do a similar error for functions: 57b0ae0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh scratch that, this actually avoids some other problems.
Thank you! |
similar to 281a87d