-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Generic/UnusedFunctionParameter: bug fix x 2 (magic methods and error codes) #3715
Generic/UnusedFunctionParameter: bug fix x 2 (magic methods and error codes) #3715
Conversation
ddf4dbb
to
4933983
Compare
Aren't |
4933983
to
047b254
Compare
@gsherwood Ow! Good catch. Thanks for that! I've updated the commit to exclude |
(also updated the commit description above now) |
047b254
to
767d15d
Compare
…row functions As things were, if a closure or arrow function declared within a class which extends or implements would have an unused function parameter, it would get the `InExtendedClass` or `InImplementedInterface` addition in the error code. Those additions were only intended for function declarations where the declaration would potentially be overloading a method from a parent and would have to comply with the method signature of the method in the parent class/interface. This could lead to underreporting if a standard explicitly excludes the error codes contain `InExtendedClass` and/or `InImplementedInterface`. Fixed now. Includes additional unit test, though the tests don't safeguard this much as they don't check the error codes of the messages thrown. The change can be tested manually by running the new tests against `master`, which will show: ``` 163 | WARNING | The method parameter $d is never used (Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed) 172 | WARNING | The method parameter $d is never used | | (Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed) ``` ... while with the change in this commit, this will be fixed to: ``` 163 | WARNING | The method parameter $d is never used (Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed) 172 | WARNING | The method parameter $d is never used (Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed) ```
The function signature of magic methods - with the exception of `__construct()` and `__invoke()` - is dictated by PHP and unused parameters cannot be removed, which means that the warnings for these can never be resolved, only ignored via annotations. This commit fixes this by checking whether a function is a magic method and if so, bowing out. Includes unit tests. Note: while not all magic methods take arguments, I'm still including the (nearly) full list of magic methods in the property as the other magic methods can be ignored anyway (no arguments).
767d15d
to
fcff7fa
Compare
Closing as replaced by PHPCSStandards/PHP_CodeSniffer#50 |
FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release. As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo). |
Generic/UnusedFunctionParameter: ignore class context for closures/arrow functions
As things were, if a closure or arrow function declared within a class which extends or implements would have an unused function parameter, it would get the
InExtendedClass
orInImplementedInterface
addition in the error code.Those additions were only intended for function declarations where the declaration would potentially be overloading a method from a parent and would have to comply with the method signature of the method in the parent class/interface.
This could lead to underreporting if a standard explicitly excludes the error codes contain
InExtendedClass
and/orInImplementedInterface
.Fixed now.
Includes additional unit test, though the tests don't safeguard this much as they don't check the error codes of the messages thrown.
The change can be tested manually by running the new tests against
master
, which will show:... while with the change in this commit, this will be fixed to:
Generic/UnusedFunctionParameter: ignore magic methods
The function signature of magic methods - with the exception of
__construct()
and__invoke()
- is dictated by PHP and unused parameters cannot be removed, which means that the warnings for these can never be resolved, only ignored via annotations.This commit fixes this by checking whether a function is a magic method and if so, bowing out.
Includes unit tests.
Note: while not all magic methods take arguments, I'm still including the (nearly) full list of magic methods in the property as the other magic methods can be ignored anyway (no arguments).