Chinaunix首页 | 论坛 | 博客
  • 博客访问: 162439
  • 博文数量: 46
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 466
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-31 23:12
个人简介

知乎:http://www.zhihu.com/people/chanpinjinglizhilu

文章分类

全部博文(46)

分类: 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 的配置有所区别,请自行检查。

  1. {

  2.    // *nix based systems, Mac OS X and Linux

  3.    // - All commands on and using PATHS

  4.    // We want debugging on

  5.    "show_debug": true,

  6.    // Only execute for .php files

  7.    "extensions_to_execute": ["php"],

  8.    // Do not execute for twig files

  9.    "extensions_to_blacklist": ["twig.php"],

  10.    // Execute the sniffer on file save

  11.    "phpcs_execute_on_save": false,

  12.    // Show the error list after save.

  13.    "phpcs_show_errors_on_save": true,

  14.    // Show the errors in the gutter

  15.    "phpcs_show_gutter_marks": true,

  16.    // Show outline for errors

  17.    "phpcs_outline_for_errors": true,

  18.    // Show the errors in the status bar

  19.    "phpcs_show_errors_in_status": true,

  20.    // Show the errors in the quick panel so you can then goto line

  21.    "phpcs_show_quick_panel": true,

  22.    // PHP_CodeSniffer settings

  23.    // Run the PHP_CodeSniffer

  24.    "phpcs_sniffer_run": true,

  25.    // Execute PHP_CodeSniffer on save

  26.    "phpcs_command_on_save": true,

  27.    // Path to phpcs

  28.    "phpcs_executable_path": "/usr/local/bin/phpcs",

  29.    // Run the PEAR standard without warnings

  30.    "phpcs_additional_args": {

  31.        "--standard": "PEAR",

  32.        "-n": ""

  33.    },

  34.    // PHP-CS-Fixer settings

  35.    // Do not automatically fix the errors

  36.    "php_cs_fixer_on_save": false,

  37.    // Show the fixes in the quick panel

  38.    "php_cs_fixer_show_quick_panel": true,

  39.    // Path to where php-cs-fixer.phar is

  40.    "php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer",

  41.    // Run all levels of fixing

  42.    "php_cs_fixer_additional_args": {

  43.    },

  44.    // PHP Linter settings

  45.    // Lint each file

  46.    "phpcs_linter_run": true,

  47.    // Execute the linter on save

  48.    "phpcs_linter_command_on_save": true,

  49.    // Use the $PATH version of php

  50.    "phpcs_php_path": "/usr/local/bin/phpcs",

  51.    // Regex for the errors the linter produces

  52.    "phpcs_linter_regex": "(?P.*) on line (?P\d+)",

  53.    // PHP Mess Detector settings

  54.    // Execute phpmd

  55.    "phpmd_run": true,

  56.    // Execute the phpmd on file save

  57.    "phpmd_command_on_save": true,

  58.    // Path to where the phpmd application is

  59.    "phpmd_executable_path": "/usr/local/bin/phpmd",

  60.    // What args I want to pass to phpmd

  61.    "phpmd_additional_args": {

  62.        "codesize,unusedcode,naming": ""

  63.    },

  64.    // PHP Scheck settings

  65.    // Execute scheck

  66.    "scheck_run": false,

  67.    // Execute the scheck on file save

  68.    "scheck_command_on_save": false,

  69.    // It seems python/sublime cannot always find the scheck application

  70.    // If empty, then use PATH version of scheck, else use the set value

  71.    "scheck_executable_path": "",

  72.    // Additional arguments you can specify into the application

  73.    "scheck_additional_args": {

  74.        "-strict" : ""

  75.    }

  76. }


4.完成



PS:如submit 出现报错,可显示调试信息调试具体问题 Ctrl+~;如再有问题,可联系我。



阅读(3147) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~