Created
June 23, 2017 09:16
-
-
Save bloatfan/ae315f76c940faf1bc0758e8264dd3cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| standard="OSR0" | |
| phpcsVersion="2.9.1" | |
| function phpcsEvnCheck() | |
| { | |
| # check phpcs exist | |
| which phpcs > /dev/null 2>&1 | |
| if [ $? != 0 ] | |
| then | |
| echo '请检查 phpcs 执行文件是否在系统 $PATH 变量中' | |
| exit 1 | |
| fi | |
| # check phpcs version | |
| if [ "$phpcsVersion" != "" ] | |
| then | |
| phpcs --version | grep $phpcsVersion > /dev/null 2>&1 | |
| if [ $? != 0 ] | |
| then | |
| echo " | |
| 请检查你安装的 phpcs 的版本,要求 | |
| PHP_CodeSniffer version $phpcsVersion (stable) by Squiz (http://www.squiz.net) | |
| " | |
| fi | |
| fi | |
| # check if install OSR | |
| phpcs -i | grep $standard > /dev/null 2>&1 | |
| if [ $? != 0 ] | |
| then | |
| echo " | |
| 请先将 $standard 标准添加到 phpcs 可使用标准路径中 | |
| 请执行 phpcs -i 查看是否一下输出 | |
| The installed coding standards are MySource, PEAR, PHPCS, PSR1, PSR2, Squiz, Zend and $standard | |
| 如果输出中不包含 $standard,请执行以下命令将 $standard 标准加入 phpcs 可使用标准路径中 | |
| 注意:将 $OSR_PROJECT_PATH 变量替换成你从 Gitlab 获取的 OSR 项目存放在本地中的路径 | |
| phpcs --config-set installed_paths $OSR_PROJECT_PATH/Standards | |
| " | |
| exit 1 | |
| fi | |
| } | |
| phpcsEvnCheck | |
| files=`git diff --name-only --cached --diff-filter='ACMR' | grep '.php$'` | |
| if [ "$files" != "" ] | |
| then | |
| tmpFile="/tmp/tmp_$$" | |
| phpcs -q --standard=$standard $files > $tmpFile | |
| if [ $? != 0 ] | |
| then | |
| cat $tmpFile | |
| rm $tmpFile | |
| exit 1 | |
| fi | |
| rm $tmpFile | |
| fi | |
| echo 'good job' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment