简体   繁体   English

phpcs - 防止显示“多行 function 调用的左括号必须是该行的最后一个内容”

[英]phpcs - Prevent showing "Opening parenthesis of a multi-line function call must be the last content on the line"

The error occur for this code:此代码发生错误:

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

I'm using phpcs vscode and need all of the default rules of phpcs except this one!我正在使用phpcs vscode,需要phpcs的所有默认规则,除了这个!

Could you please tell me how to你能告诉我怎么做吗

  1. Write a phpcs with all of the default rules编写一个包含所有默认规则的 phpcs
  2. How to exclude this rule如何排除此规则

You can use ruleset.xml with this content您可以使用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>

And then add this line in Phpcs: standards settings.json in VS code然后在 Phpcs 中添加这一行:standard settings.json in VS code

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

More information about ruleset you can find here有关规则集的更多信息,您可以在此处找到

You can use ruleset.xml with this content您可以使用 ruleset.xml 与此内容

<?xml version="1.0"?>
<ruleset name="Oximox">
   <!--
      The name attribute of the ruleset tag is displayed
      when running PHP_CodeSniffer with the -v command line
      argument. The description tag below is not displayed anywhere
      except in this file, so it can contain information for
      developers who may change this file in the future.
   -->
   <description>Custom Coding Standards</description>

   <!--
      Include all sniffs in the PSR2 standard. Note that the
      path to the standard does not have to be specified as the
      PSR2 standard exists inside the PHP_CodeSniffer install
      directory.
   -->
   <rule ref="PSR2"/>

   <rule ref="PSR2">
        <exclude name="PSR2.Functions.FunctionCallSignature.ContentAfterOpenBracket"/>
        <exclude name="PSR2.Functions.FunctionCallSignature.CloseBracketLine"/>
    </rule>
</ruleset>

It worked for me.它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM