记录时间:2019-08-01 ***** **问题来源** 为规范php团队开发的规范及提高团队成员对规范的重要意识,研究想让成员们了解自己的代码到底有多么的不规范而提出实现的 **composer全局安装 php_codesniffer** 小问题记录:由于一直没有安装新的composer包,去下载的时候告诉我,下载不下来,原来laravel-org镜像下服了,切换到阿里云吧。 ``` // 可以通过composer -gl 查看自己的镜像地址 composer global require "squizlabs/php\_codesniffer=\*“ // 设置全局默认使用规范: phpcs --config-set default\_standard PSR2 phpcbf --config-set default\_standard PSR2 ``` **使用** Phpcs 可以检测代码 Phpcbf可以修复代码(仅格式,不含逻辑) 具体使用方法,可以查看文档 https://packagist.org/packages/squizlabs/php_codesniffer **使用下的提示大概解析(翻译不正确还请包涵)** ``` End of line character is invalid; expected "\n" but found "\r\n" 表示换行符不是PSR2规范制定的,规范使用LF,但是发现CRLF Line exceeds 120 characters; contains 142 characters 超出120个字符,规定的是120个字符 Method name "Test::test_1_1" is not in camel caps format 方法名称不是驼峰格式的 Whitespace found at end of line 结尾行出现空白符(回车换行CRLF也会导致该错) Opening brace indented incorrectly; expected 0 spaces, found 4 左大括号缩进错误,需要四个空格 ``` 这里就不一一解析了,大家百度翻译吧