yiisoft/yii2-coding-standards – Eternal Night https://www.shuijingwanwq.com There is no problem not worth solving, and no technology not worth learning! Fri, 05 Jun 2026 13:29:13 +0000 en-US hourly 1 https://wordpress.org/?v=7.0 Set the PHP code sniffer to Code Sniffer in Windows 10 64, PHPStorm to verify that your code complies with Yii 2 Web Framework Coding Standard (Yii 2 Web) framework coding standard) https://www.shuijingwanwq.com/en/2018/03/23/15873/ https://www.shuijingwanwq.com/en/2018/03/23/15873/#respond Fri, 23 Mar 2018 05:55:57 +0000 https://www.shuijingwanwq.com/?p=15873 浏览量: 1

1. Reference URL:https://github.com/yiisoft/yii2-coding-standards, as shown in Figure 1

参考网址:https://github.com/yiisoft/yii2-coding-standards

Figure 1

2. Clone the yiisoft/yii2-coding-standards warehouse, as shown in Figure 2

克隆 yiisoft/yii2-coding-standards 仓库

Figure 2

3. Enter the E:\wwwroot\yii2-coding-standards directory, and execute the installation, as shown in Figure 3
cd .\yii2-coding-standards\
composer install

进入 E:\wwwroot\yii2-coding-standards 目录,执行安装,

Figure 3

4. Configure the local PHP interpreter, File | Settings → Languages & Frameworks → PHP → CLI Interpreter drop-down list, as shown in Figure 4

配置本地PHP解释器,File | Settings → Languages & Frameworks → PHP → CLI Interpreter 下拉列表旁边的按钮

Figure 4

5. CLI interpreters → add → other local. If you already have a local interpreter configured in phpstorm, it will also appear on the menu and the menu item will change to other local, as shown in Figure 5

CLI Interpreters → Add → Other Local。如果您已经在 PhpStorm 中配置了本地解释器,则它也会显示在菜单上,并且菜单项将更改为 Other Local

Figure 5

6. CLI interpreters → add → other local → OK, as shown in Figure 6

CLI Interpreters → Add → Other Local → Local → OK

Figure 6

7. Configure the local PHP interpreter as local, as shown in Figure 7

配置本地PHP解释器为 Local

Figure 7

8. Select the code sniffer script to use, file | settings → languages & frameworks → php → code sniffer → configuration: The button next to the Local drop-down list, as shown in Figure 8

选择使用的代码嗅探器脚本,File | Settings → Languages & Frameworks → PHP → Code Sniffer → Configuration: Local下拉列表旁边的按钮

8

9. File | Settings → Languages & frameworks → php → code sniffer → php code sniffer path:e:\wwwroot\yii2-coding-standards\vendor\bin\phpcs.bat, as shown in Figure 9
Reference command: ./vendor/bin/phpcs –extensions=php –standard=yii2 /home/resurrtm/work/yii2megaapp/

File | Settings → Languages & Frameworks → PHP → Code Sniffer → PHP Code Sniffer path:E:\wwwroot\yii2-coding-standards\vendor\bin\phpcs.bat

Figure 9

10. Click the Validate button, if the verification is successful, phpstorm will display the detected code sniffer version information, as shown in Figure 10

单击 Validate 按钮,如果验证通过成功,PhpStorm 将显示​​检测到的代码嗅探器版本信息

Figure 10

11. Configure the local code sniffer script to succeed, as shown in Figure 11

配置本地代码嗅探器脚本成功

Figure 11

12. Configure the php code sniffer to phpstorm check, file | settings → editor → inspects → php → php code sniffer validation, as shown in Figure 12

将PHP代码嗅探器配置为PhpStorm检查,File | Settings → Editor → Inspections → PHP → PHP Code Sniffer validation

Figure 12

13. Yii uses PSR-1 and PSR-2 as the code style standard, File | Settings → Editor → Code style → PHP → set from… → predefined style → PSR1/PSR2, as shown in Figure 13

Yii使用PSR-1和PSR-2作为代码风格标准,File | Settings → Editor → Code Style → PHP → Set from... → Predefined Style → PSR1/PSR2

Figure 13

14. Run the code sniffer in batch mode, code | inspect code → inspect scope: whole project, as shown in Figure 14

在批处理模式下运行代码嗅探器,Code | Inspect code → Inspection scope: Whole project

Figure 14

15. View the inspection results in the Inspect Results Tool Window, the error and warning reported by the PHP code sniffer have a PHPCS prefix to distinguish it from the PHPStorm internal check, as shown in Figure 15

在 Inspection Results Tool Window 中查看检查结果,PHP代码嗅探器报告的错误和警告具有phpcs前缀以区别于PhpStorm内部检查

Figure 15

16. Click Group by Severity (group by severity), you can give priority to the problem of the highest severity, as shown in Figure 16

Server Problem Server Issue
typo typo
info information
weak warning
warning warning
error error
unused entry unused entry

点击 Group by Severity(按严重程度分组),可以优先解决严重程度最高的问题

Figure 16

]]>
https://www.shuijingwanwq.com/en/2018/03/23/15873/feed/ 0