From 74a071efbaa9ae255da6d56d36585b1aa7579942 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Tue, 27 Aug 2019 13:36:14 +0800 Subject: [PATCH 01/23] =?UTF-8?q?=E4=BC=98=E5=8C=96composer=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e0bc0c3..1cb4490 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,16 @@ { "name": "webergiles/php-csc", + "keywords": ["psr", "psr-11", "phpcs", "phpcsc"], + "license": "MIT", "description": "PHP code style check 利用git hook、phplint、phpcs在git commit的时候对php代码进行语法检测、代码风格检查,如果有问题,不允许提交。", "type": "library", "require": { "php": ">=7.1", "squizlabs/php_codesniffer": "3.*", - "overtrue/phplint": "1.1.9" + "overtrue/phplint": "1.*" }, "require-dev": { - "php": "^7." + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "bin": [ "bin/phpcsc" From d1b63bde86b815d06219b047891746ca15b8f633 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Tue, 27 Aug 2019 14:12:11 +0800 Subject: [PATCH 02/23] =?UTF-8?q?=E4=BC=98=E5=8C=96=200.0.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++-- bin/phpcsc | 100 +++++++++++--------------------------------------- composer.json | 6 +++ pre-commit | 4 +- 4 files changed, 32 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index 0477446..adc8972 100755 --- a/README.md +++ b/README.md @@ -11,11 +11,10 @@ composer require --dev webergiles/php-csc # 指令 -指令 (composer exec -v phpcc {指令} | 用法 +指令 (composer exec -v phpcsc {指令} | 用法 --- | --- | -install | 安装php-cc -remove | 移除php-cc -config | 配置 +install | 安装php-csc +remove | 移除php-csc #注意事项 phpcsc的pre-commit会覆盖原有的pre-commit,但仍然会将它备份为pre-commit.bak.{timestamp}。所以之前有在pre-commit中插入操作,请谨慎安装。 diff --git a/bin/phpcsc b/bin/phpcsc index fa8296b..8581d58 100755 --- a/bin/phpcsc +++ b/bin/phpcsc @@ -1,11 +1,18 @@ #!/usr/bin/env php Date: Tue, 27 Aug 2019 14:25:06 +0800 Subject: [PATCH 03/23] =?UTF-8?q?=E4=BC=98=E5=8C=96=200.0.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/phpcsc | 13 ++++++++++--- composer.json | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bin/phpcsc b/bin/phpcsc index 8581d58..c1a20f3 100755 --- a/bin/phpcsc +++ b/bin/phpcsc @@ -57,10 +57,17 @@ function install() echo $phpCsCheckRs[0] . "\n"; } # check&&back pre-commit - if (is_file('./.git/hooks/pre-commit')) { - //exec('mv ./.git/hooks/pre-commit ./.git/hooks/pre-commit.bak.' . time()); + if (is_file('./.git/hooks/pre-commit') + && md5_file('./.git/hooks/pre-commit') != md5_file('./vendor/webergiles/php-csc/pre-commit')) { + exec('mv ./.git/hooks/pre-commit ./.git/hooks/pre-commit.bak.' . time()); } - //exec('cp ./vendor/webergiles/php-csc/pre-commit ./.git/hooks'); + if (is_file('./.git/hooks/pre-commit') + && md5_file('./.git/hooks/pre-commit') == md5_file('./vendor/webergiles/php-csc/pre-commit')) { + echo "php-csc install success!\n"; + exit(0); + } + + exec('cp ./vendor/webergiles/php-csc/pre-commit ./.git/hooks'); echo "php-csc install success!\n"; exit(0); diff --git a/composer.json b/composer.json index 4c059a8..8e26811 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ } ], "scripts": { - "post-package-install": "./bin/phpcsc install", - "post-package-update": "./bin/phpcsc install", + "post-update-cmd": "./bin/phpcsc install", + "post-install-cmd": "./bin/phpcsc install", "post-package-uninstall": "./bin/phpcsc remove" }, From 8241bf2034a5365c1ed99cbf2de4f6ef018d1ec6 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Tue, 27 Aug 2019 14:35:17 +0800 Subject: [PATCH 04/23] =?UTF-8?q?=E4=BC=98=E5=8C=96=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pre-commit | 124 +++++++++++++++-------------------------------------- 1 file changed, 35 insertions(+), 89 deletions(-) diff --git a/pre-commit b/pre-commit index a87b05f..98cd8ed 100755 --- a/pre-commit +++ b/pre-commit @@ -1,97 +1,43 @@ -#!/usr/bin/env bash - -function askContinue() { - read -p "Errors found, input [y/yes] to continue to commit:" content - if [[ ${content} == "y" || ${content} == "yes" ]] ;then - echo "Errors found, but continue to commit" - exit 0 - fi - echo "Abort to commit ~" - exit 1 -} - -# 引入配置文件 -# read config file -source ./vendor/webergiles/php-csc/phpcsc.ini +#!/bin/sh + +PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"` +STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php` + +# Determine if a file list is passed +if [ "$#" -eq 1 ] +then + oIFS=$IFS + IFS=' + ' + SFILES="$1" + IFS=$oIFS +fi +SFILES=${SFILES:-$STAGED_FILES_CMD} -# 检查phplint的命令路径是否配置 -# 如果没有配置,则使用默认的路径 -# 如果配置了,则进一步检查配置的路径是否正确 -# check if phplint_path is config -if [[ x"$phplint_path" = x ]]; then - phplint_path="./vendor/bin/phplint" -else - ${phplint_path} --version > /dev/null - if [[ $? -ne 0 ]]; then - echo "Command phplint error, please check it and retry~" +echo "Checking PHP Lint..." +for FILE in $SFILES +do + php -l -d display_errors=0 $PROJECT/$FILE + if [ $? != 0 ] + then + echo "Fix the error before commit." exit 1 fi -fi + FILES="$FILES $PROJECT/$FILE" +done -# 检查phpcs的命令路径是否配置 -# 如果没有配置,则使用默认的路径 -# 如果配置了,则进一步检查配置的路径是否正确 -# check if phpcs_path is config -if [[ x"$phpcs_path" = x ]]; then - phpcs_path="phpcs" -else - ${phpcs_path} --version > /dev/null - if [[ $? -ne 0 ]]; then - echo "Command phpcs error, please check it and retry~" +if [ "$FILES" != "" ] +then + echo "Running Code Sniffer. Code standard PSR2." + ./vendor/bin/phpcs --standard=PSR12 --colors --encoding=utf-8 -n -p $FILES + if [ $? != 0 ] + then + echo "Fix the error before commit!" + echo "Run" + echo " ./vendor/bin/phpcs --standard=PSR2 $FILES" + echo "for automatic fix or fix it manually." exit 1 fi fi -# 获取本次提交的差异文件 -a=`git status -s` - -array=(${a//,/ }) -for var in ${array[@]} -do - if [[ "$var" = "M" ]] || [[ "$var" = "A" ]] || [[ "$var" = "D" ]]; then - continue - fi - - # check php file - if [[ ! ${var} =~ ".php" ]]; then - echo "Check file $var: not php file, ignoring..." - continue - fi - - # phplint - if [[ ${phplint} == "true" ]]; then - phplintResult=`${phplint_path} $var | grep error` - if [[ x"$phplintResult" != x ]]; then - echo "-------------------------------------" - echo "Git commit error, get phplint errors:" - ${phplint_path} ${var} | while read line - do - echo ${line} - done - askContinue - exit 1 - else - echo "phplint file [$var] success !" - fi - fi - - # phpcs - if [[ ${phpcs} == "true" ]]; then - phpcsResult=`${phpcs_path} -n --standard=psr2 ${var} | grep ERROR | grep -v "0 ERRORS\|exist\|usage"` - if [[ x"$phpcsResult" != x ]]; then - echo "-------------------------------------" - echo "Git commit error, get phpcs errors:" - ${phpcs_path} -n --standard=psr2 ${var} | while read line - do - echo ${line} - done - askContinue - exit 1 - else - echo "phpcs file [$var] success !" - fi - fi -done - -echo "Congratulations! Code check success!" -exit 0 +exit $? From d91d1b6118287dcbf52d1320169c5d07ff1bdb36 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Tue, 27 Aug 2019 14:43:57 +0800 Subject: [PATCH 05/23] =?UTF-8?q?=E4=BC=98=E5=8C=96=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 8e26811..2dcecf6 100644 --- a/composer.json +++ b/composer.json @@ -22,9 +22,9 @@ } ], "scripts": { - "post-update-cmd": "./bin/phpcsc install", - "post-install-cmd": "./bin/phpcsc install", - "post-package-uninstall": "./bin/phpcsc remove" + "post-package-update": "php ./bin/phpcsc install", + "post-package-install": "php ./bin/phpcsc install", + "post-package-uninstall": "php ./bin/phpcsc remove" }, "minimum-stability": "dev" From 0f3b58c4c76d19091c803731386fa5c0f8133180 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Tue, 27 Aug 2019 14:53:46 +0800 Subject: [PATCH 06/23] =?UTF-8?q?=E4=BC=98=E5=8C=96=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/phpcsc | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/phpcsc b/bin/phpcsc index c1a20f3..91a7929 100755 --- a/bin/phpcsc +++ b/bin/phpcsc @@ -6,8 +6,6 @@ $action = [ 'install', 'remove' ]; -var_dump($argv); - if (empty($argv[1]) || !in_array($argv[1], $action)) { print<< Date: Wed, 28 Aug 2019 10:01:22 +0800 Subject: [PATCH 07/23] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PHPCodeChecker.php | 106 ++++++++++++++++++++++++++++ pre-commit => src/pre-commit | 0 src/pre-commit.ps1 | 131 +++++++++++++++++++++++++++++++++++ src/pre-commit.win | 4 ++ 4 files changed, 241 insertions(+) create mode 100644 src/PHPCodeChecker.php rename pre-commit => src/pre-commit (100%) create mode 100755 src/pre-commit.ps1 create mode 100755 src/pre-commit.win diff --git a/src/PHPCodeChecker.php b/src/PHPCodeChecker.php new file mode 100644 index 0000000..c4f48f7 --- /dev/null +++ b/src/PHPCodeChecker.php @@ -0,0 +1,106 @@ + + * Date: 2019/8/28 + * Time: 09:35 + */ + +namespace MountHooks; + +class PHPCodeChecker +{ + protected static $DS = DIRECTORY_SEPARATOR; + + public static function hookInstall() + { + self::checkEnvironment(); + + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + self::installWindows(); + } else { + self::installNoWindows(); + } + } + + /** + * 检测本地环境 + */ + private static function checkEnvironment() + { + # check git + echo "Checking git repository...\n"; + if (!is_dir(".". self::$DS .".git")) { + echo "Your project has not been init by git! Please check it...\n"; + exit(1); + } + + # check phplint + echo "Checking phplint install...\n"; + exec('.'. self::$DS .'vendor'. self::$DS .'bin'. self::$DS .'phplint --version', $phpLintCheckRs, $returnVar); + if ($returnVar) { + echo "Checking phplint failed! Please install phplint first!"; + exit(1); + } else { + echo "Checking phplint success!\n"; + echo $phpLintCheckRs[0] . "\n"; + } + + # check phpcs + echo "Checking phpcs install...\n"; + exec('.'. self::$DS .'vendor'. self::$DS .'bin'. self::$DS .'phpcs --version', $phpCsCheckRs, $returnVar); + if ($returnVar) { + echo "Checking phpcs failed! Please install phpcs first!"; + exit(1); + } else { + echo "Checking phpcs success!\n"; + echo $phpCsCheckRs[0] . "\n"; + } + } + + /** + * 挂载非Windows机器的git hooks + */ + private static function installNoWindows() + { + # check&&back pre-commit + if (is_file('./.git/hooks/pre-commit') + && md5_file('./.git/hooks/pre-commit') != md5_file('./vendor/webergiles/php-csc/pre-commit')) { + system('mv ./.git/hooks/pre-commit ./.git/hooks/pre-commit.bak.' . time()); + } + if (is_file('./.git/hooks/pre-commit') + && md5_file('./.git/hooks/pre-commit') == md5_file('./vendor/webergiles/php-csc/pre-commit')) { + echo "php-csc install success!\n"; + exit(0); + } + + system('cp ./vendor/webergiles/php-csc/src/pre-commit ./.git/hooks'); + system('chmod +x .git/hooks/pre-commit'); + + echo "php-csc install success!\n"; + exit(0); + } + + /** + * 挂载非Windows机器的git hooks + */ + private static function installWindows() + { + # check&&back pre-commit + if (is_file('.\.git\hooks\pre-commit') + && md5_file('.\.git\hooks\pre-commit') != md5_file('.\vendor\webergiles\php-csc\pre-commit')) { + system('xcopy /s /f /y .\.git\hooks\pre-commit .\.git\hooks\pre-commit.bak.' . time()); + } + if (is_file('.\.git\hooks\pre-commit') + && md5_file('.\.git\hooks\pre-commit') == md5_file('.\vendor\webergiles\php-csc\pre-commit')) { + echo "php-csc install success!\n"; + exit(0); + } + + system('xcopy /s /f /y "vendor\webergiles\php-csc\src\pre-commit.win" ".git\hooks\pre-commit"'); + system('xcopy /s /f /y "vendor\webergiles\php-csc\src\pre-commit.ps1" ".git\hooks\pre-commit.ps1"'); + + echo "php-csc install success!\n"; + exit(0); + } +} diff --git a/pre-commit b/src/pre-commit similarity index 100% rename from pre-commit rename to src/pre-commit diff --git a/src/pre-commit.ps1 b/src/pre-commit.ps1 new file mode 100755 index 0000000..73e3abd --- /dev/null +++ b/src/pre-commit.ps1 @@ -0,0 +1,131 @@ +############################################################################### +# +# PHP Syntax Check for Git pre-commit hook for Windows PowerShell +# +# Author: Vojtech Kusy <wojtha@gmail.com> +# Author: Chuck "MANCHUCK" Reeves <chuck@manchuck.com> +# Author: Andrew 'Ziggy' Dempster +# +############################################################################### + +### INSTRUCTIONS ### + +# Place the code to file "pre-commit" (no extension) and add it to the one of +# the following locations: +# 1) Repository hooks folder - C:\Path\To\Repository\.git\hooks +# 2) User profile template - C:\Users\<USER>\.git\templates\hooks +# 3) Global shared templates - C:\Program Files (x86)\Git\share\git-core\templates\hooks +# +# The hooks from user profile or from shared templates are copied from there +# each time you create or clone new repository. + +### SETTINGS ### + +# Path to the php.exe +$php_exe = "C:\php\php.exe"; + +# Path to the phpcs +$php_cs = "phpcs"; + +# Extensions of the PHP files +$php_ext = 'php|module|inc|install|test|profile|theme|txt|class'; + +# Flag, if set to $true git will unstage all files with errors, set to $false to disable +$unstage_on_error = 0; + +### FUNCTIONS ### + +## PHP Lint +function php_syntax_check { + param([string]$php_bin, [string]$extensions, [bool]$reset) + + $err_counter = 0; + $file_counter = 0; + + write-host "PHP syntax check:" -foregroundcolor "white" -backgroundcolor "black" + + # loop through all commited files + git diff-index --name-only --cached --diff-filter=AM HEAD -- | foreach { + # only match php files + if ($_ -match ".*\.($extensions)$") { + $file_counter++; + $file = $matches[0]; + $errors = & $php_bin -l $file + + write-host $file ": " -foregroundcolor "gray" -backgroundcolor "black" -NoNewline + if ($errors -match "No syntax errors detected in $file") { + write-host "OK!" -foregroundcolor "green" -backgroundcolor "black" + } else { + write-host "ERROR! " $errors -foregroundcolor "red" -backgroundcolor "black" + if ($reset) { + git reset -q HEAD $file + write-host "Unstaging ..." -foregroundcolor "magenta" -backgroundcolor "black" + } + $err_counter++ + } + } + } + + # output report + write-host "Checked" $file_counter "File(s)" -foregroundcolor "gray" -backgroundcolor "black" + if ($err_counter -gt 0) { + write-host "Some File(s) have syntax errors. Please fix then commit" -foregroundcolor "red" -backgroundcolor "black" + exit 1 + } +} + +# PHP Code Sniffer Check +function php_cs_check { + param([string]$php_cs, [string]$extensions, [bool]$reset) + + $err_counter = 0; + $file_counter = 0; + + write-host "PHP codesniffer check:" -foregroundcolor "white" -backgroundcolor "black" + + # Loop through all commited files + git diff-index --name-only --cached --diff-filter=AM HEAD -- | foreach { + # only run lint if file extensions match + if ($_ -match ".*\.($extensions)$") { + $file_counter++; + $file = $matches[0]; + + write-host $file ": " -foregroundcolor "gray" -backgroundcolor "black" -NoNewline + + # skip test files + if ($file -match "test\/") { + write-host "SKIPPED! (test file)" -foregroundcolor "darkGreen" -backgroundcolor "black" + } else { + $errors = & $php_cs --standard=Drupal $file + + # Outputs the error + if ($LastExitCode) { + write-host "FAILED! (contains errors)" -foregroundcolor "red" -backgroundcolor "black" + write-host + write-output $errors + if ($reset) { + git reset -q HEAD $file + write-host "Unstaging ..." -foregroundcolor "magenta" -backgroundcolor "black" + } + $err_counter++ + } else { + write-host "PASSED!" -foregroundcolor "green" -backgroundcolor "black" + } + } + } + } + + # output report + write-host "Checked" $file_counter "File(s)" -foregroundcolor "gray" -backgroundcolor "black" + if ($err_counter -gt 0) { + write-host "Some File(s) are not following proper codeing standards. Please fix then commit" -foregroundcolor "red" -backgroundcolor "black" + exit 1 + } +} + +### MAIN ### +php_syntax_check $php_exe $php_ext $unstage_on_error +write-host + +php_cs_check $php_cs $php_ext $unstage_on_error +write-host \ No newline at end of file diff --git a/src/pre-commit.win b/src/pre-commit.win new file mode 100755 index 0000000..7c3c906 --- /dev/null +++ b/src/pre-commit.win @@ -0,0 +1,4 @@ +#!/bin/sh +echo +exec powershell.exe -ExecutionPolicy RemoteSigned -File '.\.git\hooks\pre-commit.ps1' +exit \ No newline at end of file From 15f0330a5e2a679db63a0c7c41facfed6613c7fe Mon Sep 17 00:00:00 2001 From: WangGeng Date: Wed, 28 Aug 2019 11:17:10 +0800 Subject: [PATCH 08/23] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PHPCodeChecker.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/PHPCodeChecker.php b/src/PHPCodeChecker.php index c4f48f7..694e230 100644 --- a/src/PHPCodeChecker.php +++ b/src/PHPCodeChecker.php @@ -15,7 +15,6 @@ class PHPCodeChecker public static function hookInstall() { self::checkEnvironment(); - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { self::installWindows(); } else { From 426915d84672cfe59024c3629bb8c94c5dd0e0fe Mon Sep 17 00:00:00 2001 From: WangGeng Date: Wed, 28 Aug 2019 11:23:35 +0800 Subject: [PATCH 09/23] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81luoji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 5 +++++ src/PHPCodeChecker.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2dcecf6..f371c30 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,11 @@ "email": "giles.wang@qq.com" } ], + "autoload": { + "psr-4": { + "WeberGiles\\MountHooks\\": "src/" + } + }, "scripts": { "post-package-update": "php ./bin/phpcsc install", "post-package-install": "php ./bin/phpcsc install", diff --git a/src/PHPCodeChecker.php b/src/PHPCodeChecker.php index 694e230..ffb9f98 100644 --- a/src/PHPCodeChecker.php +++ b/src/PHPCodeChecker.php @@ -6,7 +6,7 @@ * Time: 09:35 */ -namespace MountHooks; +namespace WeberGiles\MountHooks; class PHPCodeChecker { From 62226cd89ce2f6fb469a12ba3e1c78525cb95531 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Wed, 28 Aug 2019 11:54:12 +0800 Subject: [PATCH 10/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PHPCodeChecker.php | 84 ++++++++++++++++++------------------------ src/pre-commit.win | 3 +- 2 files changed, 37 insertions(+), 50 deletions(-) diff --git a/src/PHPCodeChecker.php b/src/PHPCodeChecker.php index ffb9f98..579cea1 100644 --- a/src/PHPCodeChecker.php +++ b/src/PHPCodeChecker.php @@ -8,35 +8,34 @@ namespace WeberGiles\MountHooks; +defined('DS') || define('DS', DIRECTORY_SEPARATOR); // 目录分隔符简写 + class PHPCodeChecker { protected static $DS = DIRECTORY_SEPARATOR; public static function hookInstall() { - self::checkEnvironment(); - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - self::installWindows(); - } else { - self::installNoWindows(); - } + $os = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'windows' : 'author'; + self::checkEnvironment($os); } /** - * 检测本地环境 + * 挂载git hook + * @param string $os 默认环境 winodws */ - private static function checkEnvironment() + private static function checkEnvironment($os = 'windows') { # check git echo "Checking git repository...\n"; - if (!is_dir(".". self::$DS .".git")) { + if (!is_dir(".". DS .".git")) { echo "Your project has not been init by git! Please check it...\n"; exit(1); } # check phplint echo "Checking phplint install...\n"; - exec('.'. self::$DS .'vendor'. self::$DS .'bin'. self::$DS .'phplint --version', $phpLintCheckRs, $returnVar); + exec('.'. DS .'vendor'. DS .'bin'. DS .'phplint --version', $phpLintCheckRs, $returnVar); if ($returnVar) { echo "Checking phplint failed! Please install phplint first!"; exit(1); @@ -47,7 +46,7 @@ private static function checkEnvironment() # check phpcs echo "Checking phpcs install...\n"; - exec('.'. self::$DS .'vendor'. self::$DS .'bin'. self::$DS .'phpcs --version', $phpCsCheckRs, $returnVar); + exec('.'. DS .'vendor'. DS .'bin'. DS .'phpcs --version', $phpCsCheckRs, $returnVar); if ($returnVar) { echo "Checking phpcs failed! Please install phpcs first!"; exit(1); @@ -55,49 +54,36 @@ private static function checkEnvironment() echo "Checking phpcs success!\n"; echo $phpCsCheckRs[0] . "\n"; } - } - /** - * 挂载非Windows机器的git hooks - */ - private static function installNoWindows() - { - # check&&back pre-commit - if (is_file('./.git/hooks/pre-commit') - && md5_file('./.git/hooks/pre-commit') != md5_file('./vendor/webergiles/php-csc/pre-commit')) { - system('mv ./.git/hooks/pre-commit ./.git/hooks/pre-commit.bak.' . time()); - } - if (is_file('./.git/hooks/pre-commit') - && md5_file('./.git/hooks/pre-commit') == md5_file('./vendor/webergiles/php-csc/pre-commit')) { - echo "php-csc install success!\n"; - exit(0); - } + if (is_file('.'. DS .'.git'. DS .'hooks'. DS .'pre-commit')) { + $fileOldMd5 = md5_file('.'. DS .'.git'. DS .'hooks'. DS .'pre-commit'); - system('cp ./vendor/webergiles/php-csc/src/pre-commit ./.git/hooks'); - system('chmod +x .git/hooks/pre-commit'); + $fileNewMd5 = $os == 'windows' + ? md5_file('.'. DS .'vendor'. DS .'webergiles'. DS .'php-csc'. DS .'src'. DS .'pre-commit.win') + : md5_file('.'. DS .'vendor'. DS .'webergiles'. DS .'php-csc'. DS .'src'. DS .'pre-commit'); - echo "php-csc install success!\n"; - exit(0); - } - - /** - * 挂载非Windows机器的git hooks - */ - private static function installWindows() - { - # check&&back pre-commit - if (is_file('.\.git\hooks\pre-commit') - && md5_file('.\.git\hooks\pre-commit') != md5_file('.\vendor\webergiles\php-csc\pre-commit')) { - system('xcopy /s /f /y .\.git\hooks\pre-commit .\.git\hooks\pre-commit.bak.' . time()); - } - if (is_file('.\.git\hooks\pre-commit') - && md5_file('.\.git\hooks\pre-commit') == md5_file('.\vendor\webergiles\php-csc\pre-commit')) { - echo "php-csc install success!\n"; - exit(0); + if ($fileOldMd5 == $fileNewMd5) { + echo "php-csc install success!\n"; + exit(0); + } else { + if ($os == 'windows') { + system('xcopy /s /f /y + .'. DS .'vendor'. DS .'webergiles'. DS .'php-csc'. DS .'src'. DS .'pre-commit + .'. DS .'.git'. DS .'hooks'. DS .'pre-commit.bak.'. time()); + } else { + system('mv .'. DS .'.git'. DS .'hooks'. DS .'pre-commit + .'. DS .'.git'. DS .'hooks'. DS .'pre-commit.bak.' . time()); + } + } } - system('xcopy /s /f /y "vendor\webergiles\php-csc\src\pre-commit.win" ".git\hooks\pre-commit"'); - system('xcopy /s /f /y "vendor\webergiles\php-csc\src\pre-commit.ps1" ".git\hooks\pre-commit.ps1"'); + if ($os == 'windows') { + system('xcopy /s /f /y "vendor\webergiles\php-csc\src\pre-commit.win" ".git\hooks\pre-commit"'); + system('xcopy /s /f /y "vendor\webergiles\php-csc\src\pre-commit.ps1" ".git\hooks\pre-commit.ps1"'); + } else { + system('cp ./vendor/webergiles/php-csc/src/pre-commit ./.git/hooks'); + system('chmod +x .git/hooks/pre-commit'); + } echo "php-csc install success!\n"; exit(0); diff --git a/src/pre-commit.win b/src/pre-commit.win index 7c3c906..506c2e9 100755 --- a/src/pre-commit.win +++ b/src/pre-commit.win @@ -1,4 +1,5 @@ #!/bin/sh +#@version 0.0.13 echo exec powershell.exe -ExecutionPolicy RemoteSigned -File '.\.git\hooks\pre-commit.ps1' -exit \ No newline at end of file +exit From 518df95902988d3a19a9e472db30b4c9596051b3 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Wed, 28 Aug 2019 13:43:24 +0800 Subject: [PATCH 11/23] =?UTF-8?q?windows=20=E7=BB=88=E7=89=88=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PHPCodeChecker.php | 15 +++++---------- src/pre-commit.ps1 | 6 +++--- 2 files changed, 8 insertions(+), 13 deletions(-) mode change 100755 => 100644 src/pre-commit.ps1 diff --git a/src/PHPCodeChecker.php b/src/PHPCodeChecker.php index 579cea1..5d93102 100644 --- a/src/PHPCodeChecker.php +++ b/src/PHPCodeChecker.php @@ -57,29 +57,24 @@ private static function checkEnvironment($os = 'windows') if (is_file('.'. DS .'.git'. DS .'hooks'. DS .'pre-commit')) { $fileOldMd5 = md5_file('.'. DS .'.git'. DS .'hooks'. DS .'pre-commit'); - $fileNewMd5 = $os == 'windows' ? md5_file('.'. DS .'vendor'. DS .'webergiles'. DS .'php-csc'. DS .'src'. DS .'pre-commit.win') : md5_file('.'. DS .'vendor'. DS .'webergiles'. DS .'php-csc'. DS .'src'. DS .'pre-commit'); - if ($fileOldMd5 == $fileNewMd5) { echo "php-csc install success!\n"; exit(0); } else { if ($os == 'windows') { - system('xcopy /s /f /y - .'. DS .'vendor'. DS .'webergiles'. DS .'php-csc'. DS .'src'. DS .'pre-commit - .'. DS .'.git'. DS .'hooks'. DS .'pre-commit.bak.'. time()); + system('ren .git'. DS .'hooks'. DS .'pre-commit pre-commit.bak.'. time()); } else { - system('mv .'. DS .'.git'. DS .'hooks'. DS .'pre-commit - .'. DS .'.git'. DS .'hooks'. DS .'pre-commit.bak.' . time()); + $oldHook ='.'. DS .'.git'. DS .'hooks'. DS .'pre-commit'; + system('mv '. $oldHook .' .'. DS .'.git'. DS .'hooks'. DS .'pre-commit.bak.' . time()); } } } - if ($os == 'windows') { - system('xcopy /s /f /y "vendor\webergiles\php-csc\src\pre-commit.win" ".git\hooks\pre-commit"'); - system('xcopy /s /f /y "vendor\webergiles\php-csc\src\pre-commit.ps1" ".git\hooks\pre-commit.ps1"'); + system('copy vendor\webergiles\php-csc\src\pre-commit.win .git\hooks\pre-commit'); + system('copy vendor\webergiles\php-csc\src\pre-commit.ps1 .git\hooks\pre-commit.ps1'); } else { system('cp ./vendor/webergiles/php-csc/src/pre-commit ./.git/hooks'); system('chmod +x .git/hooks/pre-commit'); diff --git a/src/pre-commit.ps1 b/src/pre-commit.ps1 old mode 100755 new mode 100644 index 73e3abd..1c9c5fa --- a/src/pre-commit.ps1 +++ b/src/pre-commit.ps1 @@ -22,10 +22,10 @@ ### SETTINGS ### # Path to the php.exe -$php_exe = "C:\php\php.exe"; +$php_exe = "php.exe"; # Path to the phpcs -$php_cs = "phpcs"; +$php_cs = "vendor\bin\phpcs"; # Extensions of the PHP files $php_ext = 'php|module|inc|install|test|profile|theme|txt|class'; @@ -96,7 +96,7 @@ function php_cs_check { if ($file -match "test\/") { write-host "SKIPPED! (test file)" -foregroundcolor "darkGreen" -backgroundcolor "black" } else { - $errors = & $php_cs --standard=Drupal $file + $errors = & $php_cs --standard=PSR12 --colors --encoding=utf-8 -n -p $file # Outputs the error if ($LastExitCode) { From 718db494d1ec18a9ff602cfa166b6893606cde45 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Wed, 28 Aug 2019 13:51:00 +0800 Subject: [PATCH 12/23] =?UTF-8?q?windows=20=E7=BB=88=E7=89=88=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 21 +++++++++++++++++++++ bin/phpcsc | 2 +- src/PHPCodeChecker.php | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index adc8972..cc2f896 100755 --- a/README.md +++ b/README.md @@ -16,5 +16,26 @@ composer require --dev webergiles/php-csc install | 安装php-csc remove | 移除php-csc +# composer 自动挂载 +在主项目composer 文件中增加事件 +```json +"post-package-install": [ + "WeberGiles\\MountHooks\\PHPCodeChecker::hookInstall" +], +"post-package-update": [ + "WeberGiles\\MountHooks\\PHPCodeChecker::hookInstall" +], +"post-install-cmd": [ + "WeberGiles\\MountHooks\\PHPCodeChecker::hookInstall" +], +"post-update-cmd": [ + "WeberGiles\\MountHooks\\PHPCodeChecker::hookInstall" +], +"post-package-uninstall": [ + "WeberGiles\\MountHooks\\PHPCodeChecker::hookUnstall" +] + +``` + #注意事项 phpcsc的pre-commit会覆盖原有的pre-commit,但仍然会将它备份为pre-commit.bak.{timestamp}。所以之前有在pre-commit中插入操作,请谨慎安装。 diff --git a/bin/phpcsc b/bin/phpcsc index 91a7929..e95c035 100755 --- a/bin/phpcsc +++ b/bin/phpcsc @@ -79,6 +79,6 @@ function remove() exec('rm -f .git/hooks/pre-commit'); } - echo "Remove phpcc success!\n"; + echo "Remove phpcsc success!\n"; exit(0); } diff --git a/src/PHPCodeChecker.php b/src/PHPCodeChecker.php index 5d93102..134968b 100644 --- a/src/PHPCodeChecker.php +++ b/src/PHPCodeChecker.php @@ -20,6 +20,21 @@ public static function hookInstall() self::checkEnvironment($os); } + public static function hookUnstall() + { + $os = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'windows' : 'author'; + if ($os == 'windows') { + system('ren .git'. DS .'hooks'. DS .'pre-commit pre-commit.bak.'. time()); + echo "Remove phpcsc success!\n"; + exit(0); + } else { + $oldHook ='.'. DS .'.git'. DS .'hooks'. DS .'pre-commit'; + system('mv '. $oldHook .' .'. DS .'.git'. DS .'hooks'. DS .'pre-commit.bak.' . time()); + echo "Remove phpcsc success!\n"; + exit(0); + } + } + /** * 挂载git hook * @param string $os 默认环境 winodws From e82fd185ae63718206d481290e9d6ccd2f86a7c1 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Wed, 28 Aug 2019 15:10:59 +0800 Subject: [PATCH 13/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index cc2f896..fdfaf8d 100755 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ PHP code style check 利用git hook、phplint、phpcs在git commit的时候对php代码进行语法检测、代码风格检查,如果有问题,不允许提交。 # 使用 -composer require --dev webergiles/php-csc +composer require --dev webergiles/php-csc "0.*" 安装成功之后执行`composer exec phpcsc install`该命令会检查phplint、phpcs的安装情况,并将git原有的pre-commit钩子备份,再将php-cc的pre-commit钩子拷贝至.git/hooks中。 @@ -19,22 +19,12 @@ remove | 移除php-csc # composer 自动挂载 在主项目composer 文件中增加事件 ```json -"post-package-install": [ +"post-autoload-dump": [ "WeberGiles\\MountHooks\\PHPCodeChecker::hookInstall" ], -"post-package-update": [ - "WeberGiles\\MountHooks\\PHPCodeChecker::hookInstall" -], -"post-install-cmd": [ - "WeberGiles\\MountHooks\\PHPCodeChecker::hookInstall" -], -"post-update-cmd": [ - "WeberGiles\\MountHooks\\PHPCodeChecker::hookInstall" -], -"post-package-uninstall": [ +"pre-package-uninstall": [ "WeberGiles\\MountHooks\\PHPCodeChecker::hookUnstall" ] - ``` #注意事项 From d2381c50bf262ec3f867fb61e9231ac72d469247 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Wed, 28 Aug 2019 16:10:02 +0800 Subject: [PATCH 14/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 6 ------ src/PHPCodeChecker.php | 2 -- 2 files changed, 8 deletions(-) diff --git a/composer.json b/composer.json index f371c30..5a3e151 100644 --- a/composer.json +++ b/composer.json @@ -26,11 +26,5 @@ "WeberGiles\\MountHooks\\": "src/" } }, - "scripts": { - "post-package-update": "php ./bin/phpcsc install", - "post-package-install": "php ./bin/phpcsc install", - "post-package-uninstall": "php ./bin/phpcsc remove" - - }, "minimum-stability": "dev" } diff --git a/src/PHPCodeChecker.php b/src/PHPCodeChecker.php index 134968b..c898223 100644 --- a/src/PHPCodeChecker.php +++ b/src/PHPCodeChecker.php @@ -26,12 +26,10 @@ public static function hookUnstall() if ($os == 'windows') { system('ren .git'. DS .'hooks'. DS .'pre-commit pre-commit.bak.'. time()); echo "Remove phpcsc success!\n"; - exit(0); } else { $oldHook ='.'. DS .'.git'. DS .'hooks'. DS .'pre-commit'; system('mv '. $oldHook .' .'. DS .'.git'. DS .'hooks'. DS .'pre-commit.bak.' . time()); echo "Remove phpcsc success!\n"; - exit(0); } } From 95fb5d0b4d9ce4ffa7dc82414830638fd13bbf21 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Wed, 28 Aug 2019 17:09:48 +0800 Subject: [PATCH 15/23] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpcsc.ini | 9 --------- 1 file changed, 9 deletions(-) delete mode 100755 phpcsc.ini diff --git a/phpcsc.ini b/phpcsc.ini deleted file mode 100755 index dd05ac6..0000000 --- a/phpcsc.ini +++ /dev/null @@ -1,9 +0,0 @@ -# config for phplint -phplint=true -phplint_path=./vendor/bin/phplint - -# config for phpcs -phpcs=true -phpcs_path=./vendor/bin/phpcs -phpcs_ignore= -phpcs_standard=psr12 From b4001fb801db679656e0b4dfb8d1c57e62be86ec Mon Sep 17 00:00:00 2001 From: WangGeng Date: Thu, 29 Aug 2019 10:08:08 +0800 Subject: [PATCH 16/23] =?UTF-8?q?=E5=A2=9E=E5=8A=A0phpcpd=20phpmd=20?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5a3e151..46219e9 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,9 @@ "require": { "php": ">=7.1", "squizlabs/php_codesniffer": "3.*", - "overtrue/phplint": "1.*" + "overtrue/phplint": "1.*", + "sebastian/phpcpd": "4.*", + "phpmd/phpmd": "2.*" }, "require-dev": { "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" From 8566e738103c606b121b5e5e23a2e855159aa3ec Mon Sep 17 00:00:00 2001 From: WangGeng Date: Thu, 29 Aug 2019 10:11:27 +0800 Subject: [PATCH 17/23] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8D=95=E8=AF=8D?= =?UTF-8?q?=E6=8B=BC=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PHPCodeChecker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PHPCodeChecker.php b/src/PHPCodeChecker.php index c898223..70f47ed 100644 --- a/src/PHPCodeChecker.php +++ b/src/PHPCodeChecker.php @@ -20,7 +20,7 @@ public static function hookInstall() self::checkEnvironment($os); } - public static function hookUnstall() + public static function hookUninstall() { $os = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? 'windows' : 'author'; if ($os == 'windows') { From da8dd9d7a9f619a97ec4fd3686530881cd1a6e45 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Thu, 29 Aug 2019 10:46:53 +0800 Subject: [PATCH 18/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0composer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 46219e9..5a3e151 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,7 @@ "require": { "php": ">=7.1", "squizlabs/php_codesniffer": "3.*", - "overtrue/phplint": "1.*", - "sebastian/phpcpd": "4.*", - "phpmd/phpmd": "2.*" + "overtrue/phplint": "1.*" }, "require-dev": { "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" From 1cbcfec08b5523e76367b8fe55b585ffac472a65 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Thu, 29 Aug 2019 11:02:13 +0800 Subject: [PATCH 19/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0Readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fdfaf8d..3ceb7f5 100755 --- a/README.md +++ b/README.md @@ -2,14 +2,29 @@ PHP code style check 利用git hook、phplint、phpcs在git commit的时候对php代码进行语法检测、代码风格检查,如果有问题,不允许提交。 +# 前置要求 + - Git已安装 + - PHP安装并全局可用 下载最新版php [php-7.3.8-nts-Win32-VC15-x64.zip](https://windows.php.net/downloads/releases/php-7.3.8-nts-Win32-VC15-x64.zip) + - Composer可用 [下载 Composer](https://getcomposer.org/Composer-Setup.exe) + +## 检测原理 及流程 +- 每次git commit前是有hooks可以触发 +- 开发特定脚本,在git hooks触发的时候执行 +- 首先利用phpline检测提交文件的语法是否有错 +- 再次利用phpcs检测php的风格规范是否是否符合特定的规范 +- 符合规范 可以继续执行git push +- 不符合规范,本次commit失败,需要根据错误提示更改 +- 再次 git add && git commit + # 使用 composer require --dev webergiles/php-csc "0.*" -安装成功之后执行`composer exec phpcsc install`该命令会检查phplint、phpcs的安装情况,并将git原有的pre-commit钩子备份,再将php-cc的pre-commit钩子拷贝至.git/hooks中。 +该命令会根据本机系统检查phplint、phpcs的安装情况,并将git原有的pre-commit钩子备份, +再将php-csc的pre-commit钩子拷贝至.git/hooks中。 -这样,在git commit之前,就会执行phplint和phpcs检查待提交的文件,如果不满足要求,则会组织代码提交。 +这样,在git commit之前,就会执行phplint和phpcs检查待提交的文件,如果不满足要求,则会阻止代码提交。 -# 指令 +# 开放指令 指令 (composer exec -v phpcsc {指令} | 用法 --- | --- | @@ -26,6 +41,10 @@ remove | 移除php-csc "WeberGiles\\MountHooks\\PHPCodeChecker::hookUnstall" ] ``` +可以在没次执行composer update 的时候去检测钩子挂载情况,自动挂载钩子 #注意事项 -phpcsc的pre-commit会覆盖原有的pre-commit,但仍然会将它备份为pre-commit.bak.{timestamp}。所以之前有在pre-commit中插入操作,请谨慎安装。 +- phpcsc的pre-commit会覆盖原有的pre-commit,但仍然会将它备份为pre-commit.bak.{timestamp}。所以之前有在pre-commit中插入操作,请谨慎安装。 + +- Windows版本的PHPStorm 默认回车符\r\n 这是不符合PSR2 规范的 需要设置为\n +`File->Line Separators->LF - Unix and macOs (\n)` From 5149146b6f495a4eec0a3fcf05083d0ba827bff4 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Thu, 29 Aug 2019 11:03:48 +0800 Subject: [PATCH 20/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0Readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3ceb7f5..49d2282 100755 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ PHP code style check 利用git hook、phplint、phpcs在git commit的时候对ph # 前置要求 - Git已安装 - - PHP安装并全局可用 下载最新版php [php-7.3.8-nts-Win32-VC15-x64.zip](https://windows.php.net/downloads/releases/php-7.3.8-nts-Win32-VC15-x64.zip) - - Composer可用 [下载 Composer](https://getcomposer.org/Composer-Setup.exe) + - PHP安装并全局可用 Windows下载最新版php [php-7.3.8-nts-Win32-VC15-x64.zip](https://windows.php.net/downloads/releases/php-7.3.8-nts-Win32-VC15-x64.zip) + - Composer可用 [Windows下载 Composer](https://getcomposer.org/Composer-Setup.exe) ## 检测原理 及流程 - 每次git commit前是有hooks可以触发 From 3baca735c843cb98e7cde48d82a738a14213d28a Mon Sep 17 00:00:00 2001 From: WangGeng Date: Thu, 29 Aug 2019 11:28:54 +0800 Subject: [PATCH 21/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pre-commit.ps1 | 19 +------------------ src/pre-commit.win | 2 +- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/src/pre-commit.ps1 b/src/pre-commit.ps1 index 1c9c5fa..a9aed0e 100644 --- a/src/pre-commit.ps1 +++ b/src/pre-commit.ps1 @@ -2,25 +2,8 @@ # # PHP Syntax Check for Git pre-commit hook for Windows PowerShell # -# Author: Vojtech Kusy <wojtha@gmail.com> -# Author: Chuck "MANCHUCK" Reeves <chuck@manchuck.com> -# Author: Andrew 'Ziggy' Dempster -# ############################################################################### -### INSTRUCTIONS ### - -# Place the code to file "pre-commit" (no extension) and add it to the one of -# the following locations: -# 1) Repository hooks folder - C:\Path\To\Repository\.git\hooks -# 2) User profile template - C:\Users\<USER>\.git\templates\hooks -# 3) Global shared templates - C:\Program Files (x86)\Git\share\git-core\templates\hooks -# -# The hooks from user profile or from shared templates are copied from there -# each time you create or clone new repository. - -### SETTINGS ### - # Path to the php.exe $php_exe = "php.exe"; @@ -128,4 +111,4 @@ php_syntax_check $php_exe $php_ext $unstage_on_error write-host php_cs_check $php_cs $php_ext $unstage_on_error -write-host \ No newline at end of file +write-host diff --git a/src/pre-commit.win b/src/pre-commit.win index 506c2e9..6164c82 100755 --- a/src/pre-commit.win +++ b/src/pre-commit.win @@ -1,5 +1,5 @@ #!/bin/sh -#@version 0.0.13 +#@version 0.0.32 echo exec powershell.exe -ExecutionPolicy RemoteSigned -File '.\.git\hooks\pre-commit.ps1' exit From 16e7f70fed16c2bd4161ff3c33011625fcc67e50 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Thu, 29 Aug 2019 14:31:45 +0800 Subject: [PATCH 22/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1a67054..0e5b267 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/vendor/ +vendor/ .idea .DS_Store composer.lock From 2674681222a272fb980b27f441a05445149f5ca4 Mon Sep 17 00:00:00 2001 From: WangGeng Date: Tue, 3 Sep 2019 14:57:23 +0800 Subject: [PATCH 23/23] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49d2282..b12a3f7 100755 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ remove | 移除php-csc ``` 可以在没次执行composer update 的时候去检测钩子挂载情况,自动挂载钩子 -#注意事项 +# 注意事项 - phpcsc的pre-commit会覆盖原有的pre-commit,但仍然会将它备份为pre-commit.bak.{timestamp}。所以之前有在pre-commit中插入操作,请谨慎安装。 - Windows版本的PHPStorm 默认回车符\r\n 这是不符合PSR2 规范的 需要设置为\n