第一步:下载php code sniffer插件安装包 地址 https://github.com/benmatselby/sublime-phpcs;
第二步:下载php-cs-fixer.phar 地址 http://cs.sensiolabs.org/get/php-cs-fixer.phar ;
第三步:把php-cs-fixer.phar 放到你的 php.exe 安装目录 (例如(mine is C:/WAMP/php/php.exe));
第四步:以下内容保存为phpcs.bat,放到php.exe 安装目录;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
@
echo
off
REM PHP_CodeSniffer tokenises PHP code and detects violations of a
REM defined
set
of coding standards.
REM
REM PHP version 5
REM
REM @category PHP
REM @package PHP_CodeSniffer
REM @author Greg Sherwood <gsherwood@squiz.net>
REM @author Marc McIntyre <mmcintyre@squiz.net>
REM @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
REM @license https:
//github
.com
/squizlabs/PHP_CodeSniffer/blob/master/licence
.txt BSD Licence
REM @version CVS: $Id: phpcs.bat,
v
1.3 2007-11-04 22:02:16 squiz Exp $
REM @link http:
//pear
.php.net
/package/PHP_CodeSniffer
"@php_bin@"
-d auto_append_file=
""
-d auto_prepend_file=
""
-d include_path=
"'@php_dir@'"
-f
"@bin_dir@\phpcs"
-- %*
|
php code sniffer安装包,在子文件example-settings下有个文件
windows-7-phpcs-fixer-linter.example 就是Sublime Text 3 配置 PHPCS 的样例,还有一个nix-all-commands.example是在linux/unix环境下的配置样例
第六步:以下就是windows-7-phpcs-fixer-linter.example的配置内容,打开你的Sublime Text 3->Preferences->Package Settings -> Php Code Sniffer -> Settings - User ,复制以下内容到配置文件,注意凡是有路径的
设置都改成你本地环境下的php安装路径,保存,重启Sublime Text 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
{
//
Path to php on windows installation
//
This is needed as we cannot run phars on windows, so we run it through php
"phpcs_php_prefix_path"
:
"C:\\wamp\bin\\php\\php5.4.12\\php.exe"
,
//
This is the path to the bat
file
when we installed PHP_CodeSniffer
"phpcs_executable_path"
:
"C:\\wamp\\bin\\php\\php5.4.12\\phpcs.bat"
,
//
PHP-CS-Fixer settings
//
Don't want to auto fix issue with php-cs-fixer
"php_cs_fixer_on_save"
:
false
,
//
Show the quick panel
"php_cs_fixer_show_quick_panel"
:
true
,
//
The fixer phar
file
is stored here:
"php_cs_fixer_executable_path"
:
"C:\\wamp\bin\\php\\php5.4.12\\php-cs-fixer.phar"
,
//
PHP Linter settings
//
Yes, lets lint the files
"phpcs_linter_run"
:
true
,
//
And execute that on each
file
when saved (php only as per extensions_to_execute)
"phpcs_linter_command_on_save"
:
true
,
//
Path to php
"phpcs_php_path"
:
"C:\\wamp\bin\\php\\php5.4.12\\php.exe"
,
//
This is the regex
format
of the errors
"phpcs_linter_regex"
:
"(?P<message>.*) on line (?P<line>\\d+)"
,
//
PHP Mess Detector settings
//
Not turning on the mess detector here
"phpmd_run"
:
false
,
"phpmd_command_on_save"
:
false
,
"phpmd_executable_path"
:
""
,
"phpmd_additional_args"
: {}
}
|
打开Sublime Text 3,打开php程序,语法错误提示如下图:
其实我一直用Zend Studio,感觉Sublime Text 3挺好的,小巧,插件多,没错误提示不爽就找了找怎么装插件。把安装过程写下来了,感谢http://www.cnblogs.com/meetrice/p/3731635.html这篇博客的指导