I have code that looks like this:
function processRequest() {
// get the verb
$method = strtolower($_SERVER['REQUEST_METHOD']);
switch ($method) {
case 'get':
handleGet();
break;
case 'post':
handlePost();
// $data = $_POST;
break;
case 'delete':
handleDelete();
break;
case 'options':
header('Allow: GET, POST, DELETE, OPTIONS');
break;
default:
header('HTTP/1.1 405 Method Not Allowed');
break;
}
}
PHP CodeSniffer complains about the indents of those case statements. In emacs with flymake it looks like this:

The message is:
error – Line indented incorrectly; expected 2 spaces, found 4 (PEAR.WhiteSpace.ScopeIndent.Incorrect)
Obviously CodeSniffer wants the case statements to be LESS indented than they are.
How can I tell CodeSniffer to allow my case statements to be indented the way I want them. Or better, to enforce that my case statements are indented this way?
The Sniff known as
PEAR.Whitespace.ScopeIndentis defined in code filephpcs\CodeSniffer\Standards\PEAR\Sniffs\Whitespace\ScopeIndentSniff.phpand includes the following code:See the
$nonIndentingScopes? It apparently means that anything within the scope of a switch statement is expected to not be indented with respect to the scope-opening curly.I could not find a way to tweak this setting in
PEAR.Whitespace.ScopeIndent, but…. that Sniff extends the more basicGeneric.Whitespace.ScopeIndent, which does not includeT_SWITCHin the$nonIndentingScopesarray.So what I did to allow my case statements the way I wanted was to modify my ruleset.xml file, to exclude the PEAR version of that sniff, and include the Generic version of that sniff. It looks like this:
This file needs to be present in a subdir under the Standards directory for PHP CodeSniffer. For me, the file location is
\dev\phpcs\CodeSniffer\Standards\MyStandard\ruleset.xmlThen I run phpcs like this:
\php\php.exe \dev\phpcs\scripts\phpcs --standard=MyStandard --report=emacs -s file.php