PhpStorm添加PHP代码规范检查CodeSniffer(phpcs)和PHP代码静态分析工具Mess Detector(phpmd)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PhpStorm添加PHP代码规范检查CodeSniffer(phpcs)和PHP代码静态分析工具Mess Detector(phpmd)相关的知识,希望对你有一定的参考价值。
一、安装
添加镜像,加速下载
./composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com
CodeSniffer
composer.phar global require "squizlabs/php_codesniffer=*"
Mess Detector
composer.phar global require "phpmd/phpmd=*"
二、PhpStorm配置phpcs, phpmd位置
File -> Default Setting -> Language & Frameworks -> Code Sniffer -> Config[Local] 点击 ... 按钮 -> path: C:\Users\{username}\AppData\Roaming\Composer\vendor\bin\phpcs.bat
File -> Default Setting -> Language & Frameworks -> Mess Detector -> Config[Local] 点击 ... 按钮 -> path: C:\Users\{username}\AppData\Roaming\Composer\vendor\bin\phpmd.bat
三、PhpStorm启用phpcs, phpmd
File -> Default Setting -> Editor -> Inspections -> PHP -> PHP Code Sniffer validation (打上勾)-> Coding standard -> PSR2 -> Apply
File -> Default Setting -> Editor -> Inspections -> PHP -> PHP Mess Detector validation (打上勾)-> Options(选择相应规则) -> Apply
以上是关于PhpStorm添加PHP代码规范检查CodeSniffer(phpcs)和PHP代码静态分析工具Mess Detector(phpmd)的主要内容,如果未能解决你的问题,请参考以下文章
PHP工具篇:PHPStorm IDE使用CodeSniffer代码规范化管理
phpStorm 配置PHP_CodeSniffer自动检查代码