Skip to content

Instantly share code, notes, and snippets.

@mlocati
Created November 8, 2016 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlocati/ec7de6c4fdd91c1af83c50a6c341457a to your computer and use it in GitHub Desktop.
Save mlocati/ec7de6c4fdd91c1af83c50a6c341457a to your computer and use it in GitHub Desktop.
Call php-cs-fixer by automatically locating the configuration file
@echo off
setlocal enabledelayedexpansion
if "%~1" equ "" (
echo Missing file name>&2
goto :eof
)
if "%~2" neq "" (
echo Too many arguments>&2
goto :eof
)
if not exist "%~1" (
echo File not found: %~1>&2
goto :eof
)
if exist "%~1\*.*" (
echo File needed: %~1 is a directory>&2
goto :eof
)
set FILENAME=%~dpnx1
set DIRNAME=%~dp1
set DIRNAME=%DIRNAME:~0,-1%
:checkParent
set CONFIG=%DIRNAME%\.php_cs
if exist "%CONFIG%" goto :found
call :getParent %DIRNAME% DIRNAME
if "%DIRNAME%" equ "." (
echo Configuration file not found>&2
goto :eof
)
goto checkParent
:found
C:\Dev\PHP7.0-64\php.exe "%~dp0php-cs-fixer.phar" fix --config-file="%CONFIG%" "%FILENAME%"
goto :eof
:getParent
set %2=.
if "%1" equ "." exit /b
if "%1" equ "" exit /b
set P1=%~dp1
set P2=%P1:~0,-1%
if "%P2:~0,2%" equ "%P2:~0,3%" exit /b
set %2=%P2%
exit /b
@WinterSilence
Copy link

notepad nppExec

cls
php -f "scripts/php-cs-fixer.phar" fix "$(FULL_CURRENT_PATH)" --config="scripts/.php_cs.dist" --diff
npp_open $(FULL_CURRENT_PATH)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment