Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:13:32+00:00 2026-05-31T02:13:32+00:00

I have code that looks like this: function processRequest() { // get the verb

  • 0

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:

enter image description here

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:13:33+00:00Added an answer on May 31, 2026 at 2:13 am

    The Sniff known as PEAR.Whitespace.ScopeIndent is defined in code file phpcs\CodeSniffer\Standards\PEAR\Sniffs\Whitespace\ScopeIndentSniff.php and includes the following code:

    class PEAR_Sniffs_WhiteSpace_ScopeIndentSniff extends Generic_Sniffs_WhiteSpace_ScopeIndentSniff
    {
        /**
         * Any scope openers that should not cause an indent.
         *
         * @var array(int)
         */
        protected $nonIndentingScopes = array(T_SWITCH);
    
    }//end class
    

    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 basic Generic.Whitespace.ScopeIndent, which does not include T_SWITCH in the $nonIndentingScopes array.

    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:

    <?xml version="1.0"?>
    <ruleset name="Custom Standard">
      <!-- http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php -->
      <description>My custom coding standard</description>
    
      <rule ref="PEAR">
             ......
        <exclude name="PEAR.WhiteSpace.ScopeIndent"/>
      </rule>
    
       ....
    
      <!-- not PEAR -->
      <rule ref="Generic.WhiteSpace.ScopeIndent">
        <properties>
          <property name="indent" value="2"/>
        </properties>
      </rule>
    
    </ruleset>
    

    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.xml

    Then I run phpcs like this:

    \php\php.exe \dev\phpcs\scripts\phpcs --standard=MyStandard --report=emacs -s file.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that looks like this : Function ExecuteAndLogError(Of TResult)(ByVal code As
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I have some code that looks like this: someFunc(value) { switch(value){ case 1: case
I have certain code that I want to optimize. It looks like this: function
i have javascript code that looks like this: $('#lnkPopup').click(function() { var id = $(this).attr('rel');
I have a little bit of code that looks just like this: function StrippedExample(i1,
I have code that looks like this.... function Finder(id) { this.id = id; this.input
I have code, that looks something like this: (function($) { $(document).ready(function() { function getHash(){
I have code that looks like this: function foobar(array& $objects, $con = null) {
So I have a code that looks something like this $(.something).live({ mouseover:function(e){ //do stuff

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.