首页 > 代码库 > PhpStorm添加PHP代码规范检查CodeSniffer(phpcs)和PHP代码静态分析工具Mess Detector(phpmd)

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)