ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] > [IDEA 官方设置](https://www.jetbrains.com/help/phpstorm/using-php-code-sniffer.html#installing-configuring-code-sniffer) > [参考](http://jintang.zone/2017/12/21/PHP%E9%9D%99%E6%80%81%E4%BB%A3%E7%A0%81%E6%89%AB%E6%8F%8F%E5%B7%A5%E5%85%B7%E7%9A%84%E4%BD%BF%E7%94%A8.html) ## 概述 - 新创项目创建,推荐同时 `Php_CodeSniffer`,`Mess Detector`, `PHP CS Fixer` - 会在每次的 commit 提交时,进行设置 说明 ``` phpcs (php code sniffer) PHP代码嗅探器
 phpcbf (php code beautiful fixer) PHP代码美化器
 php-cs-fixer,另一个PHP代码规范修复器 ``` ## PHP_CodeSniffer(phpcs) ### 安装 ``` composer global require "squizlabs/php_codesniffer=*" or composer require --dev "squizlabs/php_codesniffer=*" ``` ### 配置 ``` File | Settings | Languages & Frameworks | PHP | Quality Tools | PHP_CodeSniffer ``` 点按钮后进入 `PHP_CodeSniffer` 选项 ![](https://img.kancloud.cn/c8/52/c85259be2e5a04d953c2a4fb765e0b9d_824x238.png) 添加 `C:\Users\jiuqi\AppData\Roaming\Composer\vendor\bin\phpcs.bat` 到 PATH 中 ![](https://img.kancloud.cn/73/eb/73eb6bb979fe288e5d0e20b56070551a_758x419.png) 勾选 `PHP_CodeSniffer validation` ,并设置 `Coding strandard` 设置为 `PSR12` ### phpcbs 在安装 phpcs 时,会同时安装一个 phpcbf ,可自定进行格式的转变,语法 ``` phpcbf --standard=PSR12 .\demo1.php ``` ## Mess Detector ### 安装 ``` composer global require "phpmd/phpmd" or composer require --dev "phpmd/phpmd" ``` ### 配置与PHP_CodeSniffer同理 参考路径 ``` C:\Users\jiuqi\AppData\Roaming\Composer\vendor\bin\phpmd.bat ``` 配置参考 ![](https://img.kancloud.cn/b5/39/b53916daf314e48858eeb988b31895a3_775x482.png) 推荐不要勾选 Naming Rules 规则,它会要求变量名必须大于3 ## PHP CS Fixer ### 安装 ``` composer global require friendsofphp/php-cs-fixer or composer require --dev friendsofphp/php-cs-fixer ``` ### 配置与PHP_CodeSniffer同理 参考路径 ``` C:\Users\jiuqi\AppData\Roaming\Composer\vendor\bin\php-cs-fixer.bat ``` ## phplint ### 安装 ``` composer require --dev overtrue/phplint ``` ## 结合到 IDAE ![](https://img.kancloud.cn/9c/2c/9c2c20a435aa9aed18fdff11422666fc_1061x716.png) > 并录制宏, `Edit | Macros`,录制:先点击 `Code | Reforamt Code` 和`Code | Optimeize Imports` ,结束录制,并设置快捷键,为 `Ctrl+Alt+L` ## 导出配置 `File | Settings | Editor | Inspections` 导出配置