通过 GIT 钩子实现 PHP 格式整理与语法校验
步骤概括
- 【下载phpcbf】到本地目录(下载地址见文档底部)
> 例如:
> Linux: ~/.composer/vendor/bin/phpcbf
> Windows: c:spacesoftsystemphpcbf.phar
- 【创建hooks】或修改hooks文件:.git/hooks/pre-commit
- 【复制下方脚本】到pre-commit
- 【修改路径】代码中phpcbf和php
Windows环境注意:
> 例如:
> Linux: ~/.composer/vendor/bin/phpcbf
> Windows: c:spacesoftsystemphpcbf.phar
Windows环境注意:
当提示
hint: The '.git/hooks/pre-commit' hook was ignored because it's not set as executable.
hint: You can disable this warning with `git config advice.ignoredHook false`.
是因为钩子文件没有运行权限,根据情况赋予钩子文件执行权限即可,例如:
chmod 700 .git/hooks/pre-commit
场景:yaf 中 controller 类不能指定 namespace,导致无法通过 PSR2 规范检测
由于域名被 紫田网络 恶意抢注,并冒充排版助手官网,导致排版助手和吉特盒子频繁弹出错误警告。
现提供临时修复办法:
msgid "Welcome to My PHP Application"
msgstr "欢迎访问我的PHP应用"
若环境没有msgfmt工具,请顺手安装:
sudo apt-get install gettext
或
yum install gettext-devel