【问题标题】:phpcs - Prevent showing "Opening parenthesis of a multi-line function call must be the last content on the line"phpcs - 防止显示“多行函数调用的左括号必须是该行的最后一个内容”
【发布时间】:2019-12-27 20:19:12
【问题描述】:

此代码出现错误:

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

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

你能告诉我怎么做吗

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

【问题讨论】:

  • 检查{后面是否有空格。
  • @u_mulder 勾选,红线在App\Post::whereHas(下方,谢谢
  • 如果可以的话,你可能应该change the default coding standard 到 PSR2(PEAR 是默认值)。
  • @Jeto 谢谢,这为我解决了! ???截至 2019 年 8 月 10 日,PSR-2 已标记为deprecated。现在建议将PSR-12 作为替代方案。所以:phpcs --config-set default_standard PSR12

标签: php visual-studio-code codesniffer phpcs phpcodesniffer


【解决方案1】:

您可以在此内容中使用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.json in VS code

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    • 2011-01-01
    • 1970-01-01
    • 2020-01-08
    • 1970-01-01
    • 2014-06-15
    • 1970-01-01
    相关资源
    最近更新 更多