0

In the coding standards that I'm using we use 2 spaces for indentation

<!-- Tabs should represent 2 spaces. -->
<arg name="tab-width" value="2"/>

<!-- Set the default indent value and force spaces instead of tabs -->
<rule ref="WordPress">
    <exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
</rule>
<rule ref="Generic.WhiteSpace.ScopeIndent">
  <properties>
    <property name="indent" value="2"/>
    <property name="tabIndent" value="false"/>
  </properties>
</rule>
<rule ref="Generic.WhiteSpace.DisallowTabIndent" />

Which is generally working fine, but if I have, for example this

<?php

class MyClass{
  public function my_function() {
    add_submenu_page(
      'my-top-level-slug',
      'My Custom Page',
      'My Custom Page',
      'manage_options',
      'my-top-level-slug'
    );
  }
}

Where the arguments of the add_submenu_page() functions are I am getting

Multi-line function call not indented correctly; expected 8 spaces but found 6

So the 'correct' would look like

<?php

class MyClass{
  public function my_function() {
    add_submenu_page(
        'my-top-level-slug',
        'My Custom Page',
        'My Custom Page',
        'manage_options',
        'my-top-level-slug'
    );
  }
}

But that's 2 spaces too much. I found some issues on github, but didn't find a solution for this.

How to fix this?

dingo_d
  • 11,160
  • 11
  • 73
  • 132

1 Answers1

1

Unfortunately, PHPCS doesn't yet have shared config settings, so you need to set the indent settings for the other sniffs that are reporting errors as well.

If you add the -s command line argument to PHPCS, you'll get a sniff code for each error message. That code tells you which sniff reported the error and needs changing.

In this case, I think it is the PEAR.Functions.FunctionCallSignature sniff.

The settings for this sniff can be found here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#pearfunctionsfunctioncallsignature

If that's the one, you'll need to add this to your ruleset:

<rule ref="PEAR.Functions.FunctionCallSignature">
  <properties>
    <property name="indent" value="2"/>
  </properties>
</rule
Greg Sherwood
  • 6,992
  • 2
  • 29
  • 24
  • That seems to be the one. So basically if I see that happening in other places I need to see which sniff is causing it, and then change the property? Thanks for the help :) – dingo_d Sep 19 '17 at 07:29
  • Yes, that's the process you'll need to go through. Glad it worked for you. – Greg Sherwood Sep 19 '17 at 22:37