0%

PhpStrom中安装CodeSniffer

环境 : windows10

本地开发环境 :phpStudy

Phpstrom版本:Phpstrom 2017.1

Phpstrom


Phpstorm是JetBrains 公司开发的跨平台的PHP IDE。在用Phpstorm编辑PHP,HTML和JavaScript的代码时,Phpstorm提供实施代码分析,错误提示和自动格式化等功能。支持的PHP版本包括5.3, 5.4, 5.5, 5.6 和 7.0。一款便携又强大的IDE,很多功能能够帮助你更好的进行开发。

PHP CodeSniffer


PHP CodeSniffer是PEAR中的一个用PHP5写的一个PHP的代码风格检测器,它根据预先设定好的PHP编码风格和规则,去检查应用中的代码风格情况是否有违反一组预先设置好的编码标准,内置了ZEND,PEAR的编码风格规则,当然也支持自己定制。PHP CodeSniffer 是确保代码简洁一致的必不可少的开发工具,甚至还可以帮助程序员减少一些语义错误。

安装


PHP扩展安装

  1. 下载PEAR文件
  2. 切换到PHP软件目录,运行php go-pear.phar
  3. 按照提示指令输入,完成安装
  4. 装PHP Code Snifferpear install PHP_CodeSniffer
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

E:\phpStudy\php\php-5.6.27-nts>php go-pear.phar

Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :

Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type 'all' to change all of them or simply press Enter to
accept these locations.

1. Installation base ($prefix) : E:\phpStudy\php\php-5.6.27-nts
2. Temporary directory for processing : E:\phpStudy\php\php-5.6.27-nts\tmp
3. Temporary directory for downloads : E:\phpStudy\php\php-5.6.27-nts\tmp
4. Binaries directory : E:\phpStudy\php\php-5.6.27-nts
5. PHP code directory ($php_dir) : E:\phpStudy\php\php-5.6.27-nts\pear
6. Documentation directory : E:\phpStudy\php\php-5.6.27-nts\docs
7. Data directory : E:\phpStudy\php\php-5.6.27-nts\data
8. User-modifiable configuration files directory : E:\phpStudy\php\php-5.6.27-nts\cfg
9. Public Web Files directory : E:\phpStudy\php\php-5.6.27-nts\www
10. System manual pages directory : E:\phpStudy\php\php-5.6.27-nts\man
11. Tests directory : E:\phpStudy\php\php-5.6.27-nts\tests
12. Name of configuration file : C:\Windows\pear.ini
13. Path to CLI php.exe : E:\phpStudy\php\php-5.6.27-nts

1-13, 'all' or Enter to continue:
Beginning install...
Configuration written to C:\Windows\pear.ini...
Initialized registry...
Preparing to install...
installing phar://E:/phpStudy/php/php-5.6.27-nts/go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.4.2.tar...
installing phar://E:/phpStudy/php/php-5.6.27-nts/go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.4.1.tar...
installing phar://E:/phpStudy/php/php-5.6.27-nts/go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.10.3.tar...
installing phar://E:/phpStudy/php/php-5.6.27-nts/go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.1.1.tar...
installing phar://E:/phpStudy/php/php-5.6.27-nts/go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.4.2.tar...
install ok: channel://pear.php.net/Archive_Tar-1.4.2
install ok: channel://pear.php.net/Console_Getopt-1.4.1
install ok: channel://pear.php.net/Structures_Graph-1.1.1
install ok: channel://pear.php.net/XML_Util-1.4.2
install ok: channel://pear.php.net/PEAR-1.10.3
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"

** WARNING! Old version found at E:\phpStudy\php\php-5.6.27-nts, please remove it or be sure to use the new e:\phpstudy\php\php-5.6.27-nts\pear.bat command

The 'pear' command is now at your service at e:\phpstudy\php\php-5.6.27-nts\pear.bat


* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under E:\phpStudy\php\php-5.6.27-ntsPEAR_ENV.reg .
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.


E:\phpStudy\php\php-5.6.27-nts>pear install PHP_CodeSniffer
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to update
downloading PHP_CodeSniffer-2.8.1.tgz ...
Starting to download PHP_CodeSniffer-2.8.1.tgz (522,712 bytes)
.........................................................................................................done: 522,712 bytes
install ok: channel://pear.php.net/PHP_CodeSniffer-2.8.1



Phpstrom配置

  1. 下载对应的标准到Standard(E:\phpStudy\php\php-5.6.27-nts\pear\PHP\CodeSniffer\Standards)目录下面

    这里我省略了这一步

  2. 打开Phpstrom设置,依次打开Setting->Languages and Frameworks->PHP->Code Sniffer,按照下图操作
    image
  3. Standard配置,按照下图操作
    image
  4. 最好保存即可预览效果