多行函数调用未正确缩进

Multi-line function call not indented correctly

在我使用的编码标准中,我们使用 2 个空格进行缩进

<!-- 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" />

这通常工作正常,但如果我有,例如这个

<?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'
    );
  }
}

add_submenu_page() 函数的参数在哪里

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

所以 'correct' 看起来像

<?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'
    );
  }
}

但这 2 个空格太多了。我在 github 上发现了一些问题,但没有找到解决方案。

如何解决这个问题?

不幸的是,PHPCS 还没有共享配置设置,因此您还需要为报告错误的其他嗅探器设置缩进设置。

如果您将 -s 命令行参数添加到 PHPCS,您将获得每个错误消息的嗅探代码。该代码告诉您哪个嗅探器报告了错误并需要更改。

在这种情况下,我认为是 PEAR.Functions.FunctionCallSignature 嗅探。

可以在此处找到此嗅探的设置:https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#pearfunctionsfunctioncallsignature

如果是这样,您需要将其添加到您的规则集中:

<rule ref="PEAR.Functions.FunctionCallSignature">
  <properties>
    <property name="indent" value="2"/>
  </properties>
</rule