3

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!

Could you please tell me how to

  1. Write a phpcs with all of the default rules
  2. How to exclude this rule
Ali
  • 185
  • 11
  • Check if there's a space after `{`. – u_mulder Dec 27 '19 at 20:32
  • @u_mulder checked, the red line is under `App\Post::whereHas(`, thanks – Ali Dec 27 '19 at 20:54
  • 1
    If you can, you should probably [change the default coding standard](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-default-coding-standard) to PSR2 (PEAR is the default). – Jeto Dec 27 '19 at 21:09
  • 2
    @Jeto Thanks, this solved it for me! As of 2019-08-10 PSR-2 has been marked as [deprecated](https://www.php-fig.org/psr/psr-2/). [PSR-12](https://www.php-fig.org/psr/psr-12/) is now recommended as an alternative. So: `phpcs --config-set default_standard PSR12` – Pepijn Olivier May 27 '20 at 14:32

2 Answers2

1

You can use ruleset.xml with this content

<?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": "path_to_your_standard/ruleset.xml"
}

More information about ruleset you can find here

0

You can use ruleset.xml with this content

<?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.

OLIVIERS
  • 334
  • 3
  • 13