Windows装配PHP CodeSniffer,并在PHPStorm中使用

WBOY
Release: 2016-06-13 13:03:13
Original
1277 people have browsed it

Windows安装PHP CodeSniffer,并在PHPStorm中使用

Windows安装PHP CodeSniffer

1. 下载PHP_CodeSniffer 1.3.6:http://download.pear.php.net/package/PHP_CodeSniffer-1.3.6.tgz

2. 解压缩到目录:d:\dev\tools\PHP_CodeSniffer-1.3.6

3. 修改script/phpcs.bat文件

? ? ?1) @php_bin@ 替换为本地PHP执行文件路径:D:\xampp\php\php.exe

? ? ?2) @php_dir@ 替换为PHP CodeSniffer目录:d:\dev\tools\PHP_CodeSniffer-1.3.6

? ? ?3) @bin_dir@\phpcs 替换为phpcs脚本路径:d:\dev\tools\PHP_CodeSniffer-1.3.6\scripts\phpcs

? ? ?命令行如:"D:\xampp\php\php.exe" -d auto_append_file="" -d auto_prepend_file="" -d include_path="'d:\dev\tools\PHP_CodeSniffer-1.3.6'" -f "d:\dev\tools\PHP_CodeSniffer-1.3.6\scripts\phpcs" -- %*

4. 安装完成,可以用一个PHP文件测试一下:

? ? ?1) 命令行中输入:d:\dev\tools\PHP_CodeSniffer-1.3.6\scripts\phpcs.bat?test.php 可以看到类似如下的输出:

? ? ?


PHPStorm中使用PHP CodeSniffer

以PHPStorm 5为例(PS: 这个功能貌似还不是太好用,容易hung住,打开代码文件后,检查也会延迟几秒)

1. 点击菜单:File->Settings

2. 选择Project Settings下的:PHP->Code Sniffer

3. 设置PHP Code Sniffer(phpcs) path为:D:\dev\tools\PHP_CodeSniffer-1.3.6\scripts\phpcs.bat

4. 点击Validate按钮,可以看到如下提示,说明设置OK:

? ? ?

5. 选择Project Settings下的Inspections,展开PHP,勾选PHP Code Sniffer validation

6. 第一次打开的时候,需要点击一下刷新的按钮可以获取已安装的代码规范

7. 选择一个,Apply配置

? ? ?

8. 打开一个PHP文件,就可以看到不符合规则的提示

? ? ?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template