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
False positive clean code static access for Static Factory Methods #396
Comments
Are you using the StaticAccess rule? If so, then this is correct and to be expected. |
Hi,
So i assume now, the objective of this rule is to detect static dependency injections only, correct? Regards. |
Well, PHPMD is a static analysis tool. Means it has limited access in what and how it can analyze it. For you, this means you should make use of the rules' exception list as documented here:
|
Hi, However, after looking at the code, I don't think the CleanCode rules produce helpful results. For instance StaticAccess literally only scans for static method calls. Regarding your statement above:
I think we could improve StaticAccess by checking, if a static method or its subsequent method calls write to a static field or global variable. Regards. |
Most of the rules are very strict and analyze the code in a very simplistic way, thus producing potentially many false positives. When you have (potential) false positives, you have a look at them and then decide in each case, whether this is a candidate for refactoring or if you have an actual false positive (at least in your opinion) and put it onto the exception list. Changing the behavior of the StaticAccess rule is only possible in a backward compatible way, as some people might depend on its current behavior. If you want, you can try to implement a setting (which defaults to the current behavior), which makes the rule smarter the way you describe it. PRs are always welcome. |
Hi @ravage84, |
Hallo @maxmeffert , Thank you for your feedback (better late than never 😁 ). |
Hi,
I'm getting false positive warnings from clean code static access for Static Factory Methods, e.g.:
I don't know whether this is intended or not.
The text was updated successfully, but these errors were encountered: