4

I'm using Netbeans 7.1.1 with codesniffer. Whenever I have a case statement I get indentation errors, e.g. for the following code:

    switch ((int) $itemData['column_count']) {
        case 4:
            return 'grid-4columns';
        case 6:
            return 'grid-6columns';
        default:
            return '';
    }

I get "Line indented incorrectly; expected 8 spaces, found 12" for every case line. When I remove 4 spaces from those lines, e.g.

    switch ((int) $itemData['column_count']) {
    case 4:
        return 'grid-4columns';
    case 6:
        return 'grid-6columns';
    default:
        return '';
    }

I get errors "Line indented incorrectly; expected 12 spaces, found 8". Seems like codesniffer can't make up its mind, which is quite funny. The fun ends when my commits fail because of the codesniffer hook.

What is the problem with my case indentation?

UPDATE: I have only one indentation rule in my ruleset:

<rule ref="Generic.WhiteSpace.ScopeIndent" />
Oleg Ishenko
  • 2,243
  • 1
  • 15
  • 16
  • Please show which concrete codesniffer rules are used that are causing those errors. – hakre Mar 06 '13 at 10:03
  • I think, the sniffer class is `Generic_Sniffs_WhiteSpace_ScopeIndentSniff` – Oleg Ishenko Mar 06 '13 at 10:16
  • When I try this on your first code block (assuming the SWITCH is indented correctly, or not indented at all in a test file) I get no errors reported from the sniff. I used the command: `phpcs temp.php --standard=Generic --sniffs=Generic.WhiteSpace.ScopeIndent` – Greg Sherwood Mar 06 '13 at 21:24

2 Answers2

2

I had exactly the same issue using <rule ref="PEAR.WhiteSpace.ScopeIndent" /> and I fixed it just switching to <rule ref="Generic.WhiteSpace.ScopeIndent" />

claudod
  • 815
  • 8
  • 8
1

It is also possible to ignore indentation issues for specific tokens:

<!-- If you are using Generic -->
<rule ref="Generic.WhiteSpace.ScopeIndent">
    <properties>
        <property name="ignoreIndentationTokens" type="array" value="T_COMMENT,T_DOC_COMMENT_OPEN_TAG,T_CASE" />
    </properties>
</rule>

<!-- If you are using PEAR -->
<rule ref="PEAR.WhiteSpace.ScopeIndent">
    <properties>
        <property name="ignoreIndentationTokens" type="array" value="T_COMMENT,T_DOC_COMMENT_OPEN_TAG,T_CASE" />
    </properties>
</rule>

Notice the T_CASE. This prevents the sniffer from checking your case: rules.

Here is a list of tokens

rideron89
  • 491
  • 3
  • 14