Disable PHP code sniffer rules
I work with Moodle code a lot and on most (if not all) projects codesniffer is employed to ensure a degree of coding consistency and quality.
However, there are times when a specific rule is not appropriate. For example, I recently wrote a PHP fixture file for testing restyling of checkboxes and radio buttons. Since this is a fixture file, I don’t need to or want to check for a login. There are two ways I can fix this:
a) I can disable code sniffing for the entire file by adding the following to the top of the file:
// @codingStandardsIgnoreFile
b) Ignore the specific violating rule:
// phpcs:disable moodle.Files.RequireLogin.Missing
In this case solution (b) is much more preferable because it leaves the rest of the sniffs intact. Where did I get “moodle.Files.RequireLogin.Missing” from? Well, that is simply the sniff that was reported as a failure and it was outputted by codesniffer — e.g:
47 | | config inclusion. None found. (moodle.Files.RequireLogin.Missing)
After applying the rule exclusion detailed in solution (b), codesniffer will now ignore this aspect of my fixture file and everything will pass.