-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Needed interface parameters meaning is lost if class extends class that implements that interface #490
Comments
@func0der PHPCS can not look beyond the current file, but I do understand your problem. It is the reason why the sniff has modular error codes since squizlabs/PHP_CodeSniffer#1318, which allows you to choose which errors to ignore by default, like For a full list of the error codes which are available, have a look at this comment. You can use these in your custom ruleset like so (example only, customize to your own liking): <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
<!-- Allow for callback functions which may not use all parameters passed. -->
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed"/>
<!-- Allow for functions in extended classes/implemented interfaces. -->
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterface"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed"/>
</rule> |
Thanks for the quick replay. It does not feel right though to disable all those checks, because of some 'false positives'. Wouldn't that defeat the purpose of the check itself? Clearly the alternative is to ignore each and every one of those "false positives" by hand, I am just wondering if we could improve the reporting itself. Should they even be reported if there is an interface or an extending class, which would require some context awareness, I guess. |
@func0der The sniff has no access to information about classes/interfaces declared in other files, so this is the most optimal solution within the current framework. Changing the framework on which PHPCS is build, is a completely different discussion and not on the table. |
Understood. Just wanted to confirm that this is the current state. Thanks for the insights :) |
Describe the bug
Given an interface (
MailProviderInterface
) that requires a certain method signature (getConfig
).Given an (abstract) class (
AbstractMailProvider
) implementing that interface.Given a class that (
LocalMailProvider
) extends the abstract class.If not all parameters in
LocalMailProvider::getConfig()
are used, you get an error.Code sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
phpcs test.php ...
Expected behavior
The implementation of the interface from parent classes should not be forgotten.
Versions (please complete the following information)
Additional context
Please confirm
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: