这段代码出现了错误:
$posts = App\Post::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'foo%');
});
我正在使用phpcs vscode,并且需要所有默认规则,但不需要其中的一个规则!
请告诉我如何:
- 编写包含所有默认规则的phpcs
- 如何排除这个规则
这段代码出现了错误:
$posts = App\Post::whereHas('comments', function (Builder $query) {
$query->where('content', 'like', 'foo%');
});
我正在使用phpcs vscode,并且需要所有默认规则,但不需要其中的一个规则!
请告诉我如何:
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>
然后在 VS Code 中的 Phpcs: standards settings.json
中添加此行。
{
"phpcs.standard": "path_to_your_standard/ruleset.xml"
}
关于规则集的更多信息可以在这里找到
您可以使用包含此内容的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>
这对我有用。
{
后面是否有空格。 - u_mulderApp\Post::whereHas(
下面,谢谢。 - Aliphpcs --config-set default_standard PSR12
- Pepijn Olivier