用于多行函数声明的PHP CodeSniffer自定义规则集



我试图将phpcs配置为处处使用两个空格缩进,而不是4,但我被困在一个地方,我无法覆盖多行函数解密的规则

我的代码是

if (!function_exists('errorlog')) {
function errorlog(
Exception $e,
array $data = []
) {
}

尽管这个代码给了我错误,

多行函数声明缩进不正确;预期有6个空格,但找到4个

我的自定义规则集

<?xml version="1.0"?>
<ruleset name="Amit">
<description>My Custom on top of PSR2</description>
<rule ref="PSR2">
<exclude name="PSR2.Classes.ClassDeclaration"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration"/>
<exclude name="PSR2.Methods.FunctionCallSignature"/>
</rule>
<rule ref="Generic.Arrays.ArrayIndent">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<rule ref="PSR2.Classes.ClassDeclaration">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<rule ref="PSR2.ControlStructures.SwitchDeclaration">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<rule ref="PSR2.Methods.FunctionCallSignature">
<properties>
<property name="indent" value="2"/>
<property name="requiredSpacesAfterOpen" value="1"/>
<property name="requiredSpacesBeforeClose" value="1"/>
</properties>
</rule>

<rule ref="PEAR.ControlStructures.MultiLineCondition">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>

<rule ref="PEAR.Formatting.MultiLineAssignment">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
<rule ref="PEAR.Functions.FunctionDeclaration">
<properties>
<property name="indent" value="2"/>
</properties>
</rule>
</ruleset>

我获取了上面的代码,并根据提供的规则集运行它,并使用-s标志来显示Sniff报告错误。

<?php
// test.php
if (!function_exists('errorlog')) {
function errorlog(
Exception $e,
array $data = []
) {
}
}

$ ~/.composer/vendor/bin/phpcs --standard=./rules.xml -s test.php

这是我的输出:

FILE: test.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------------------
5 | ERROR | [x] Multi-line function declaration not indented correctly; expected 6 spaces but found 4 (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
6 | ERROR | [x] Multi-line function declaration not indented correctly; expected 6 spaces but found 4 (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
-------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 90ms; Memory: 6Mb

Squiz.Functions.MultiLineFunctionDeclaration.Indent是有问题的嗅探。必须想办法排除那个!

最新更新