谁有PHP_CodeSnifferqq空间自定义皮肤规则 代码 麻烦发一份呗?感激!!!

Using Grunt with PHP Quality Assurance Tools - MarietaoCMS是基于php+sqlite/mysql的国内最小(100Kb左右)的功能完善的CMS管理系统
PHP_CodeSniffer是一套用来检查代码规范的工具,是PEAR的一个包,可以通过PEAR直接安装:&pear install PHP_CodeSniffer详细的官方文档参见这里:http://pear.php.net/manual/en/package.php.php-codesniffer.php&安装完成后,多了一个phpcs命令,用法:&phpcs &参数& &文件或目录&常用的参数有:&–standard:定义代码规范,常用的有PEAR、Squiz、Zend,可以通过-i参数查看其他已安装的规范-i:查看已安装的规范-n:只显示ERROR等级的报告-s:列出违反的具体规则条目–config-set:设置配置值–config-show:列出所有已定义配置–config-delete:删除配置项–report:报告格式,常用的有summary、xml、csv,默认为full&学会基本用法后,就可以开始按报告(report)修正自己的代码了,但是有一个新的问题,就是已有的规范,要么太松,要么太紧,没有完全符合项目实际需求的规范,可能我只用到了PEAR规范中的某几条以及Squiz规范中的另外某几条,其他的一律不想让提示,于是,就需要有一套自己定义的规范了。&进入CodeSniffer的目录,一般应该在这个位置:$PEAR/PHP/CodeSniffer。&不知道PEAR安装在哪儿?好吧,用这个命令查看:pear config-get php_dir。&里边的Standards目录下,就是各种规范的定义,新建一个目录,比如我的目录叫MyCodeStanderd,进去后新建一个ruleset.xml文件,通过编写xml配置,就可以定义自己的代码规范了。&贴一段我配置的一个规范片段:&&?xml version=&1.0&?&&ruleset name=&QJP&&&&&&description&The QJP coding standard.&/description&&&&rule ref=&Generic&&& &exclude name=&Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine&/&& &exclude name=&Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine&/&&&/rule&&&&rule ref=&Generic.Formatting.MultipleStatementAlignment.IncorrectWarning&&& &message&赋值表达式格式错误,变量与“=”之间应该空%d格,实际空了%d格&/message&&&/rule&&&rule ref=&Generic.CodeAnalysis.UnusedFunctionParameter.Found&&& &message&参数%s在函数中没有用到&/message&&&/rule&&&&rule ref=&PEAR&&& &exclude name=&menting.FileComment.Missing&/&& &exclude name=&menting.ClassComment.MissingTag&/&& &exclude name=&PEAR.NamingConventions.ValidVariableName.PrivateNoUnderscore&/&&&/rule&&&&rule ref=&PEAR.NamingConventions.ValidClassName.StartWithCaptial&&& &message&类名必须大写字母开头&/message&&&/rule&&&&rule ref=&PEAR.Classes.ClassDeclaration.OpenBraceNewLine&&& &message&类定义的左花括号 { 应另起一行&/message&&&/rule&&&&rule ref=&PEAR.Functions.ValidDefaultValue.NotAtEnd&&& &message&带有默认值的参数,必须放到参数表的末端&/message&&&/rule&&&rule ref=&PEAR.Functions.FunctionDeclaration.BraceOnSameLine&&& &message&函数/方法定义的左花括号 { 应另起一行&/message&&&/rule&&&rule ref=&PEAR.WhiteSpace.ScopeClosingBrace.Line&&& &message&右花括号 } 应另起一行&/message&&&/rule&&&rule ref=&PEAR.WhiteSpace.ScopeClosingBrace.Indent&&& &message&右花括号 } 缩进空格数错误,应该为%d,实际为%d&/message&&&/rule&&&rule ref=&PEAR.WhiteSpace.ScopeIndent.Incorrect&&& &message&缩进空格数错误,应该为%d,实际为%d&/message&&&/rule&&&&rule ref=&menting.FunctionComment.Missing&&& &message&缺少函数/方法的块注释&/message&&&/rule&&&rule ref=&menting.FunctionComment.WrongStyle&&& &message&错误的块注释格式,应以 /** 开头&/message&&&/rule&&&rule ref=&menting.FunctionComment.MissingParamTag&&& &message&函数/方法的块注释中,缺少参数 %s 的说明&/message&&&/rule&&&rule ref=&menting.FunctionComment.MissingReturn&&& &message&函数/方法的块注释中,缺少 @return 标签&/message&&&/rule&&&rule ref=&menting.FunctionComment.SpacingBeforeTags&&& &message&函数/方法的块注释中,@TAG标签前需要空一行&/message&&&/rule&&&rule ref=&menting.FunctionComment.SpacingBeforeParamType&&& &message&参数注释@param中,参数类型前应该只有一个空格&/message&&&/rule&&&rule ref=&menting.FunctionComment.ParameterNamesNotAligned&&& &message&参数注释@param中,%s(%d)与%s(%d)的参数名称未对齐&/message&&&/rule&&&rule ref=&menting.FunctionComment.ParameterCommentsNotAligned&&& &message&参数注释@param中,%s(%d)与%s(%d)的参数说明未对齐&/message&&&/rule&&&rule ref=&menting.FunctionComment.ParamNameNoMatch&&& &message&参数注释@param中,参数名“%s”与实际名称不符&/message&&&/rule&&&rule ref=&menting.FunctionComment.MissingParamName&&& &message&参数注释@param中,缺少参数名称&/message&&&/rule&&&rule ref=&menting.FunctionComment.MissingParamComment&&& &message&参数注释@param中,缺少参数说明&/message&&&/rule&&&rule ref=&menting.FunctionComment.SpacingAfterParams&&& &message&最后一个参数注释@param后,应该空一行&/message&&&/rule&&&&rule ref=&Squiz.WhiteSpace.OperatorSpacing.NoSpaceBefore&&& &message&操作符前边应该有一个空格&/message&&&/rule&&&rule ref=&Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter&&& &message&操作符后边应该有一个空格&/message&&&/rule&&&/ruleset&
类别: | 阅读:19308 | 评论:0 |
想收藏或者和大家分享这篇好文章→
taoCMS发布taoCMS2.5Beta5(最后更新13年07月26日),请大家速速升级,欢迎大家试用和提出您宝贵的意见建议。
?请使用新浪微博联系我?
?在github上follow我?Install PHP CodeSniffer with Composer
A little over a month ago, I talked about how to install the PHP Code Sniffer in an MAMP-based environment . Though you can read the post in its entirety, the short of is this:
Setup Pear
Install the package via Pear
Grab the rules for the WordPress Coding Standards
Begin evaluating your code
Easy enough, right?
But here’s the thing: As mentioned in the article, some may opt to use Composer to install the package. In fact, someone also mentioned this in the comments .
And since Composer is the default dependency management application for PHPprojects, it makes sense to use it, right?
The funny thing is, since I’ve written that article, I’ve been using Composer ina few projects. So I thought it would make sense to show how to install PHP CodeSniffer with Composer.
Installing PHP CodeSniffer with Composer
To install the code sniffer with Composer assumes that you have composer installed, right? Depending on which web server setup you’re using will determine how you’ve got Composer installed.
As with the previous article, I’m going to walk through how to do it within the context of MAMP. The general steps will be the same, but the paths to, say, your PHP binaries may vary.
1. Make PHP Globally Accessible
To have access from a MAMP version ofPHP from the command line, you need to make sure that it’s part of your environmental variables.
Before going any further, make note of which version of PHP you use from within the MAMP administration screen.
Next, open terminal and enter the following command (paying attention to the version of PHP):
$&alias php=/Applications/MAMP/bin/php/php5.6.10/bin/
Now you should be able to execute PHP from the command line without having to reference the bath to the binary included with MAMP.
2. Install Composer
This is pretty easy – it’s twocommands.
First, navigate to a directory in which you want to download the Composer package. It doesn’t matter which directory you’re in because we’re going to be copying the binary to a globally accessible directory.
To download Composer, issue the following command:
$&curl -sS https://getcomposer.org/installer |
Next, move the composer.phar file into the globally accessible user binary directory:
$ mv composer.phar /usr/local/bin/
3. Verify Installation
To make sure the installation completed successfully, run the following command:
$ composer help
And you should see output like this:
If you seethat, then you’re good to go.
4. Install PHP Code Sniffer
Finally, to install PHP Code Sniffer using Composer, you can issue the following command:
$ composer global require &squizlabs/php_codesniffer=*&
Then, to install the WordPress Coding Standards sniffer, you can use the following set of commands (and read more about them in-depthin the original post).
5. Install The WordPress Coding Standards Rules
Clone a copy of the standards sniffer into the PHP binary directory. This assumes you’re working out of /Applications/MAMP/bin/php/php5.6.10/bin/php .
$ git clone :WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
Then tell the PHP Code Sniffer about the new rules:
$ phpcs --config-set installed_paths /Applications/MAMP/bin/php/php5.6.10/bin/wpcs
Finally, run $ phpcs -i and you should see the WordPress rules appear in the available set:
And, at this point, you’ve installed Composer, setup the PHP Code Sniffer using the package manager, and also configured the WordPress Coding Standards sniffer.
无相关信息
最新教程周点击榜
微信扫一扫<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&利用vim打造PHP_IDE - 推酷
利用vim打造PHP_IDE
如果你是一个vim党, 那么一切都懂得,习惯了vim,很难再回到别的编辑器或者IDE。
尝试过eclipse 、zend stdio等,PhpStorm同事有过分享,确实非常强大。但他们的缺点都是很重量级,太大、太占资源。
eclipse这些IDE各种快捷键、功能等都需要花不少时间去学习;
vim插件实在太多了, git上一大堆,实在不行还可以自己写一个;这个用的不爽那就换别的,可以玩的很开心- – ;
开始之前的声明
vim插件流本来就是有点极客的选择, 入手难度较高,新手请勿尝试
VIM VS Emacs/sublime/IDE:
仁者见仁智者见智,各有优缺点, 更不用与emacs、sublime等对比了。
IDE的优势在于开箱即用、功能强大,虽然你可能摸不到北,用不到那么强大的功能;
VIM等就具备无限的扩展性,就是一切都需要配置,不适合新手玩;
总之自己用的爽就行了。
我不打算详细的介绍每一个细节, 前面说了不适应新手玩; 毕竟如果你连如何安装插件
都不懂,自己独自折腾的难度和痛苦程度简直是令人发指的; 而且最重要的一点在于每个人
都有自己的习惯,适合自己的才是好的,”一千个vim党有一千个不同的vimrc文件”, vim配置简直
是太私人定制了;
安装插件很繁琐, 推荐使用Vundle 来管理,杀手级插件;
自动补全是IDE引以为傲的功能, 毕竟有些函数名太长太难记了。
VIM实现自动补全其实多少有点不智能,基本是靠正则瞎猜,这是相比IDE确实有所不足的地方。 不过基本也算够用。
具体实现方法:
* 原生内置:
VIM 原生内置可以使用ctrl + p ,ctrl + n 等快捷键实现上下文的自动补全;
* neocomplcache:
neocomplcache 功能非常强大, 非常流畅;
缺点是容易和别的插件冲突, 目前我在用的就是这货
* YouCompleteMe:
YouCompleteMe 是一个很不错的插件,不过很悲催的对PHP没有原生支持,但据说效果也不错, 但我没有用过
还有一些不错的插件;
没有语法高亮绝对不能活, vim默认对php有简单的高亮的, 但太弱了;
* php.vim:
看名字就懂了,专门针对php的一个插件,很给力;
不仅支持高亮,同时还附带语法检查的功能;
这个其实是php自己的语法检查,很弱,
不推荐用,可以用插件别的搞定这个事情;
* php.vim:
前面说过了,保存文件的时候会自动检查语法,少个&;&什么的都会在保存文件的时候报错提示滴;
这个在读代码或者做重构以及大项目使很用;
同样的相比IDE,vim的插件实现功能上稍微不足, taglist 会在极个别情况下不同文件中存在同名方法等会跳转错误 - -;
一般手动更新下tag文件就搞定了。
* taglist + ctags:
配置略微麻烦, 但配置完了定期更新下tags文件就好了;嫌麻烦的还可以写脚步自动更新,也可以
在拉最新主干代码使自动刷新下tags文件;
功能太强大了以至于上手难度远超taglist(视vim版本和编译参数有可能需要重新编译vim);
我目前使用较少,毕竟一般情况下taglist就足够了;
手误经常还是有的,所以必要的代码检查还是有用的;
这点是我略微有点吐槽的地方,vim 下似乎没有一个很给力的插件可以检查到php中使用了未定义的变量。
这个我是有教训的, 手误拼错了变量名导致线上bug的情况还是有的。
* php_localvarcheck:
这个可以检查代码中使用了未定义的变量, 有的话会变红提示;
但这货只支持在函数块中检查,不在函数中的就无能为力了;
一般情况下够用; 目前没发现更好的替代品了
* vim-phpqa:
大型武器来了,看名字就知道了,非常牛逼;
可以支持语法检查、代码风格审查、设计模式检查、代码命名审查、未使用的代码审查...
同时还可以自定义其他规则;
其实它是后台调用了phpcs和phpmd来实现的;
phpcs 是 PHP_CodeSniffer的简称,是PEAR中的一个用来检查PHP代码是否符合编码规范的扩展包;
phpmd 是 PHP Mess Detector 的简称,可以类比java的PMD。
选自己合适的标准和rules就好了, 太苛刻的话你会疯的; 我一般设置为:
let g:phpqa_codesniffer_args = &--standard=PSR2&
debug目前我没在用;
后续补充使用体验;
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致

我要回帖

更多关于 qq空间自定义皮肤 的文章

 

随机推荐