当我尝试创建它时,我在我的测试类中看到了警告。我不想为测试类创建 PHPDoc 和更多内容,但 PhpStorm 向我显示警告,因为 PhpStorm 无法将测试类标记为排除 phpcs。
我如何运行 phpcs 来验证我的类是否符合编码标准:
php bin/phpcs ./src -p --encoding=utf-8 --extensions=php --ignore=Tests --standard=./vendor/escapestudios/symfony2-coding-standard/Symfony2
如何为 PhpStorm 2016.3.2 实现它? 我尝试创建配置:
<target name="phpcs-ci"
description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
<exec executable="phpcs" output="/dev/null">
<arg value="--encoding=utf-8" />
<arg value="--extensions=php" />
<arg value="--ignore=Tests" />
<arg value="--standard=./vendor/escapestudios/symfony2-coding-standard/Symfony2" />
<arg path="${basedir}" />
</exec>
</target>
最佳答案
设置/首选项 |外观与行为 |范围
去那里创建一个custom Scope这将包括此类不需要的文件/文件夹(最简单的方法 - 导航到那里树中的 Tests
文件夹,然后单击 Include recursively
按钮)。
注意:理论上,如果您将带有测试的文件夹标记为“测试源根目录”(在项目 View 面板中右键单击并选择从 Mark Directory As
子菜单中选择正确的类型;同样可以通过 Settings/Preferences | Directories
完成。
这样您就可以使用内置的“测试”范围。
保存更改(
应用
... 或使用确定
并再次重新打开设置/首选项屏幕)设置/首选项 |编辑|检查
查找
PHP | PHP 代码嗅探器验证
检查为最近创建的范围创建一个新规则。
单击 In All Scopes
按钮(当只定义了 1 个规则时这是一个按钮)并选择该范围。
- 现在只需为该范围禁用此检查。
https://www.jetbrains.com/help/phpstorm/2016.3/changing-the-order-of-scopes.html
关于PhpStorm phpspec 代码嗅探器忽略测试文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42245024/