知乎:http://www.zhihu.com/people/chanpinjinglizhilu
分类: PHP
2015-05-20 14:29:54
好久没更新自己博客了,今天正好给同事们写一篇sublime 如何配置php code sniffer,发现国内还没有一个比较完善的教程,所以把它放到网上。
一、windows PHPSTORM 配置php code sniffer插件。
二、MAC OS PHPSTORM 配置php code sniffer插件。
三、MAC OS Sublime 3 配置php code sniffer插件。
一、windows PHPSTORM 配置php code sniffer插件。
1. 点击菜单:File->Settings 或 按快捷键 Ctrl+Alt+S
2. 选择Project Settings下的:PHP->Code Sniffer
3. 设置PHP Code Sniffer(phpcs) path为:E:\wamp\bin\pear\phpcs.bat (根据自己电脑情况设置)
4. 点击Validate按钮,可以看到如下提示,说明设置OK
5. 选择Project Settings下的Inspections,展开PHP,勾选PHP Code Sniffer validation
6. 第一次打开的时候,需要点击一下刷新的按钮可以获取已安装的代码规范,如果无法获取到代码规范的话,先执行 phpcs -i 命令查看PHP_CodeSniffer中已经安装的编码风格,确定有之后,尝试重启一下PhpStorm在刷新看看
7. 选择一个你习惯的编码风格,然后Apply配置
8. 打开一个PHP文件,就可以看到不符合规则的提示
二、MAC OS PHPSTORM 配置php code sniffer插件。
1. 设置PHP Code Sniffer(phpcs) path为:/usr/local/bin/phpcs
2. 点击Validate按钮,可以看到如下提示,说明设置OK
3.启用代码风格
4.演示效果
三、MAC OS Sublime 3 配置php code sniffer插件。
1.系统安装PHP_CodeSniffer、phpmd、php-cs-fixer
pear install PHP_CodeSniffer
brew install phpmd
sudo curl -o /usr/local/bin/php-cs-fixer sudo chmod a+x /usr/local/bin/php-cs-fixer
2.sublime 2 安装 phpcs插件(安装方法(Ctrl+Shift+P->pi(package install)->phpcs,安装成功后右键即可看到PHP Code Sniffer选项))
3.刚刚安装好的插件,sniff this file 显示的是灰色的,修改下配置文件(这是 Sublime 2的配置) Sublime3 的配置有所区别,请自行检查。
{
// *nix based systems, Mac OS X and Linux
// - All commands on and using PATHS
// We want debugging on
"show_debug": true,
// Only execute for .php files
"extensions_to_execute": ["php"],
// Do not execute for twig files
"extensions_to_blacklist": ["twig.php"],
// Execute the sniffer on file save
"phpcs_execute_on_save": false,
// Show the error list after save.
"phpcs_show_errors_on_save": true,
// Show the errors in the gutter
"phpcs_show_gutter_marks": true,
// Show outline for errors
"phpcs_outline_for_errors": true,
// Show the errors in the status bar
"phpcs_show_errors_in_status": true,
// Show the errors in the quick panel so you can then goto line
"phpcs_show_quick_panel": true,
// PHP_CodeSniffer settings
// Run the PHP_CodeSniffer
"phpcs_sniffer_run": true,
// Execute PHP_CodeSniffer on save
"phpcs_command_on_save": true,
// Path to phpcs
"phpcs_executable_path": "/usr/local/bin/phpcs",
// Run the PEAR standard without warnings
"phpcs_additional_args": {
"--standard": "PEAR",
"-n": ""
},
// PHP-CS-Fixer settings
// Do not automatically fix the errors
"php_cs_fixer_on_save": false,
// Show the fixes in the quick panel
"php_cs_fixer_show_quick_panel": true,
// Path to where php-cs-fixer.phar is
"php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer",
// Run all levels of fixing
"php_cs_fixer_additional_args": {
},
// PHP Linter settings
// Lint each file
"phpcs_linter_run": true,
// Execute the linter on save
"phpcs_linter_command_on_save": true,
// Use the $PATH version of php
"phpcs_php_path": "/usr/local/bin/phpcs",
// Regex for the errors the linter produces
"phpcs_linter_regex": "(?P
.*) on line (?P ,\d+)"
// PHP Mess Detector settings
// Execute phpmd
"phpmd_run": true,
// Execute the phpmd on file save
"phpmd_command_on_save": true,
// Path to where the phpmd application is
"phpmd_executable_path": "/usr/local/bin/phpmd",
// What args I want to pass to phpmd
"phpmd_additional_args": {
"codesize,unusedcode,naming": ""
},
// PHP Scheck settings
// Execute scheck
"scheck_run": false,
// Execute the scheck on file save
"scheck_command_on_save": false,
// It seems python/sublime cannot always find the scheck application
// If empty, then use PATH version of scheck, else use the set value
"scheck_executable_path": "",
// Additional arguments you can specify into the application
"scheck_additional_args": {
"-strict" : ""
}
}
4.完成
PS:如submit 出现报错,可显示调试信息调试具体问题 Ctrl+~;如再有问题,可联系我。