The StyleCI analysis has failed - PHP 语法检查

更新日期: 2017-03-11 阅读次数: 8465 分类: PHP

今天给一个 PHP 开源项目 pull request 的时候,发现 github 的代码自动检测提示我的代码有问题

The StyleCI analysis has failed

具体的错误分析

第一处:我猜测是双引号的问题

-    'delete_cancel_title'                => "放心吧",
+    'delete_cancel_title'                => '放心吧',

Laravel-Backpack/CRUD 项目根目录下有个 .styleci.yml 文件

里面只有一行配置

preset: laravel

查看 https://styleci.readme.io/docs/presets 中 Laravel 对应的部分,可以看到

single_quote - Convert double quotes to single quotes for simple strings.

果然,对于 simple string, 这里推荐使用单引号。

第二处:我猜测是使用了 TAB 作为缩进的缘故

-   // Create form - advanced options
-   'after_saving'            => '新增后',
-   'go_to_the_table_view'    => '回到总表',
-   'let_me_add_another_item' => '新增另一个记录',
-   'edit_the_new_item'       => '编辑这个记录',
+    // Create form - advanced options
+    'after_saving'            => '新增后',
+    'go_to_the_table_view'    => '回到总表',
+    'let_me_add_another_item' => '新增另一个记录',
+    'edit_the_new_item'       => '编辑这个记录',

no_tab_indentation - Code MUST use an indent of 4 spaces, and MUST NOT use tabs for indenting.

参照文档,果然如此。这是要向 python 看齐吗。。。

看一下 PSR-2: Coding Style Guide 中的解释

N.b.: Using only spaces, and not mixing spaces with tabs, helps to avoid problems with diffs, patches, history, and annotations. The use of spaces also makes it easy to insert fine-grained sub-indentation for inter-line alignment.

看来我需要调整一下 VIM 中 PHP 的配置了

autocmd FileType php setl shiftwidth=4 tabstop=4 softtabstop=4 colorcolumn=79 expandtab

像 Python 一样增加了 expandtab 设置

StyleCI 是什么

The PHP Coding Style Service

看上去目前只支持 GitHub。收费模式很有意思,如果都是开源项目那么使用 StyleCI 不收费,如果是私有项目,就需要按月付费。

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式