首页 > 解决方案 > phpcs - 防止显示“多行函数调用的左括号必须是该行的最后一个内容”

问题描述

此代码发生错误:

$posts = App\Post::whereHas('comments', function (Builder $query) {
    $query->where('content', 'like', 'foo%');
});

我正在使用phpcs vscode,需要phpcs的所有默认规则,除了这个!

你能告诉我怎么做吗

  1. 编写一个包含所有默认规则的 phpcs
  2. 如何排除此规则

标签: phpvisual-studio-codecodesnifferphpcsphpcodesniffer

解决方案


您可以使用ruleset.xml此内容

<?xml version="1.0"?>
<ruleset name="MyStandard">
    <description>My custom coding standard.</description>
    <rule ref="PEAR">
        <exclude name="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket"/>
        <exclude name="PEAR.Functions.FunctionCallSignature.CloseBracketLine"/>
    </rule>
</ruleset>

然后在 Phpcs 中添加这一行:standards settings.jsonin VS code

{
    "phpcs.standard": "path_to_your_standard/ruleset.xml"
}

有关规则集的更多信息,您可以在此处找到


推荐阅读