squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

Ignore code style issues in method signature of interface implementations #1422

Closed arnaud-lb closed 5 years ago

arnaud-lb commented 7 years ago

Sometimes we have to implement interfaces that use a different code style. For instance, the builtin SessionIdInterface in PHP has a method create_sid that violates some rules in PSR2.

It would be great if PHP_CodeSniffer could ignore any code style violation in signature of methods that are an implementation of an interface. The actual code style violation is on the interface. If the interface itself is part of the project being checked, then PHP_CodeSniffer will report a violation while analyzing the interface anyway. If it's not part of the project, then PHP_CodeSniffer will not report a violation, and this is fine, since the project can not do anything about that.

jrfnl commented 7 years ago

@arnaud-lb Which sniff are you talking about ? I can't seem to find a CamelCase sniff in PSR2... If you're unsure, run PHPCS with the -s option to see the sniff name in the report.

arnaud-lb commented 7 years ago

@jrfnl For example, PSR1.Methods.CamelCapsMethodName.NotCamelCaps. Also, PEAR.Functions.ValidDefaultValue.NotAtEnd.

jrfnl commented 7 years ago

@arnaud-lb Ah, thanks. I thought I'd send in a PR for that, but I guess that was for an external standard.

Actually - it was, I just checked. In the WPCS sniff for function names, any methods within extended classes or classes which implement an interface are ignored for precisely the reason you mention in the original issue description.

gsherwood commented 5 years ago

Closing due to the fact that changes to these sniffs would require changes in their published coding standards as well, which isn't going to happen.