I’d like to make a small change to the PEAR standard for our phpcs validation. At the moment PEAR requires you to write else statements like this:
} else {
We’d like to write them like this:
}
else {
How can I go about making this change?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only way to do this is to write your own coding standard using a ruleset.xml file. It needs to import the whole PEAR coding standard but exclude the specific sniff performing this check. This bit can be done with the single XML file.
But there are no built-in sniffs that enforce the type of
elsesyntax you are looking for. So to enforce that, you’ll need to write a custom sniff, which is more complicated as you also have to store it somewhere.If you want to start by trying the simple custom coding standard, create a file called
ruleset.xmland make this the contents:Then run PHP_CodeSniffer like this:
This will check your code against the PEAR coding standard but exclude the specific checks for control structures. If this is all you need, you can stop there. If you have a team of people you want running this custom standard, just give them the file and they can use it as well.
There is more info about the ruleset.xml format here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
If you want to go ahead and write a custom sniff, it is best to start with the basic tutorial: http://pear.php.net/manual/en/package.php.php-codesniffer.coding-standard-tutorial.php
This will explain what a coding standard is. Then, you’ll want to create your own sniff, which is just a copy of the PEAR one with slight changes for how you do control structured. The PEAR sniff is here: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PEAR/Sniffs/ControlStructures/ControlSignatureSniff.php
Without testing, I assume you’d want to change
} else {EOL',to}EOLelse {EOL',and see if that works.