好久没更新自己博客了,今天正好给同事们写一篇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插件。
- 设置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
的配置有所区别,请自行检查。
1.
{
2.
// *nix based systems, Mac OS X and Linux
3.
// - All commands on and using PATHS
4.
5.
// We want debugging on
6.
"show_debug": true,
7.
8.
// Only execute for .php files
9.
"extensions_to_execute": ["php"],
10.
11.
// Do not execute for twig files
12.
"extensions_to_blacklist": ["twig.php"],
13.
14.
// Execute the sniffer on file save
15.
"phpcs_execute_on_save": false,
16.
17.
// Show the error list after save.
18.
"phpcs_show_errors_on_save": true,
19.
20.
// Show the errors in the gutter
21.
"phpcs_show_gutter_marks": true,
22.
23.
// Show outline for errors
24.
"phpcs_outline_for_errors": true,
25.
26.
// Show the errors in the status bar
27.
"phpcs_show_errors_in_status": true,
28.
29.
// Show the errors in the quick panel so you can then goto line
30.
"phpcs_show_quick_panel": true,
31.
32.
33.
// PHP_CodeSniffer settings
34.
// Run the PHP_CodeSniffer
35.
"phpcs_sniffer_run": true,
36.
37.
// Execute PHP_CodeSniffer on save
38.
"phpcs_command_on_save": true,
39.
40.
// Path to phpcs
41.
"phpcs_executable_path": "/usr/local/bin/phpcs",
42.
43.
// Run the PEAR standard without warnings
44.
"phpcs_additional_args": {
45.
"--standard": "PEAR",
46.
"-n": ""
47.
},
48.
49.
50.
// PHP-CS-Fixer settings
51.
// Do not automatically fix the errors
52.
"php_cs_fixer_on_save": false,
53.
54.
// Show the fixes in the quick panel
55.
"php_cs_fixer_show_quick_panel": true,
56.
57.
// Path to where php-cs-fixer.phar is
58.
"php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer",
59.
60.
// Run all levels of fixing
61.
"php_cs_fixer_additional_args": {
62.
},
63.
64.
65.
// PHP Linter settings
66.
// Lint each file
67.
"phpcs_linter_run": true,
68.
69.
// Execute the linter on save
70.
"phpcs_linter_command_on_save": true,
71.
72.
// Use the $PATH version of php
73.
"phpcs_php_path": "/usr/local/bin/phpcs",
74.
75.
// Regex for the errors the linter produces
76.
"phpcs_linter_regex": "(?P.*) on line (?P\d+)",
77.
78.
79.
// PHP Mess Detector settings
80.
// Execute phpmd
81.
"phpmd_run": true,
82.
83.
// Execute the phpmd on file save
84.
"phpmd_command_on_save": true,
85.
86.
// Path to where the phpmd application is
87.
"phpmd_executable_path": "/usr/local/bin/phpmd",
88.
89.
// What args I want to pass to phpmd
90.
"phpmd_additional_args": {
91.
"codesize,unusedcode,naming": ""
92.
},
93.
94.
// PHP Scheck settings
95.
// Execute scheck
96.
"scheck_run": false,
97.
98.
// Execute the scheck on file save
99.
"scheck_command_on_save": false,
100.
101.
// It seems python/sublime cannot always find the scheck application
102.
// If empty, then use PATH version of scheck, else use the set value
103.
"scheck_executable_path": "",
104.
105.
// Additional arguments you can specify into the application
106.
"scheck_additional_args": {
107.
"-strict" : ""
108.
}
109.
}
4.完成
为知笔记图片
PS:如submit 出现报错,可显示调试信息调试具体问题 Ctrl+~;如再有问题,可联系我。
为知笔记图片
评论 (0)