重复答案的解决方案也适用于 docblock 存在检查。
这是我的酒吧课程,有评论:
<?php
namespace PhpCSTesting;
use stdClass;
/**
* Class Bar
*/
class Bar
{
/**
* @var stdClass
*/
protected $bar;
/**
* This method does stuff
*
* @return boolean
*/
public function doStuff()
{
return true;
}
}
当我运行嗅探器时,我没有收到任何错误:
bin/phpcs Bar.php --standard=Squiz --sniffs=Squiz.Commenting.FunctionComment,Squiz.Commenting.FunctionCommentThrowTag,Squiz.Commenting.ClassComment,Squiz.Commenting.VariableComment
这是我的Foo类,没有评论:
<?php
namespace PhpCSTesting;
class Foo
{
protected $bar;
public function doStuff()
{
return true;
}
}
然而,当我为这个类运行嗅探器时,我得到了错误:
bin/phpcs Foo.php --standard=Squiz --sniffs=Squiz.Commenting.FunctionComment,Squiz.Commenting.FunctionCommentThrowTag,Squiz.Commenting.ClassComment,Squiz.Commenting.VariableComment
FILE: /Users/lukas/workspace/Foo.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
5 | ERROR | Missing class doc comment
7 | ERROR | Missing member variable doc comment
9 | ERROR | Missing function doc comment
----------------------------------------------------------------------
您可以根据需要更新和修改规则集。