Skip to content

Instantly share code, notes, and snippets.

@edwint88
Created November 14, 2017 14:37
Show Gist options
  • Save edwint88/09778f622d51620b4bbfead17bcd0047 to your computer and use it in GitHub Desktop.
Save edwint88/09778f622d51620b4bbfead17bcd0047 to your computer and use it in GitHub Desktop.
Using PHP CS Fixer on CI with Mercurial (on Windows)
@echo off
ECHO "Start php-cs-fixer"
setlocal EnableDelayedExpansion
set CHANGED_FILES=
for /f "tokens=*" %%i in ('hg st -m -a -n ^| FINDSTR /s .php' ^| FINDSTR /V vendor) do (
set "CHANGED_FILES=!CHANGED_FILES! %%i"
)
IF "%CHANGED_FILES%" NEQ "" (
ECHO "It has changed files that need to be checked!"
SET "EXTRA_ARGS=--%CHANGED_FILES%"
echo "=============>>> START execute php-cs-fixer <<<============="
SET RESULT=
for /f "tokens=*" %%x in ('call /vendor-ci/bin/php-cs-fixer.bat fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no !EXTRA_ARGS!') do (
set "RESULT=!RESULT! %%x"
)
for /f "tokens=*" %%y in ('echo !RESULT! ^| FINDSTR /s "1)"') do (
set "FILES_WRONG_FORMAT=%%y"
)
echo "=============>>> FINISH execute php-cs-fixer <<<============="
IF "!FILES_WRONG_FORMAT!" NEQ "" (
echo "=============>>> Files NOT well FORMATTED! (Re-run php-cs-fixer on local machine!!) <<<============="
EXIT 1
)
) ELSE (
ECHO "NO Files were needed to be checked!"
)
EXIT 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment