Last active
December 21, 2023 15:04
-
-
Save juangacovas/ca2ad8c341ae912765eaa2e2953dc300 to your computer and use it in GitHub Desktop.
Windows cmd script for PHP lint recursive (batch script to lookup syntax errors and deprecations)
This file contains 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
@echo off | |
SETLOCAL enabledelayedexpansion | |
echo. | |
echo [107;30m Recursive PHP lint parser [0m | |
echo Will do "php -l" for all php files under given directory tree, telling deprecations and/or syntax errors. | |
echo Assumes "php.exe" is on PATH | |
echo. | |
if "%1"=="" goto :usage | |
if NOT exist "%1" ( | |
echo. | |
echo ERROR: Directroy not found: %1 | |
goto :EOF | |
) | |
goto gogogo | |
:usage | |
echo USAGE: lint path | |
echo EXAMPLE: lint ..\php\phastard\app | |
goto :EOF | |
:gogogo | |
echo Checking PHP files (php -l) at dir: %1 | |
SET n_some=0 | |
for /R "%1" %%f in (*.php) do ( | |
rem echo %%f | |
call :lookup %%f | |
IF %errorlevel% NEQ 0 ( | |
echo Aborting | |
goto :EOF | |
) | |
) | |
goto :DONE | |
:lookup | |
DEL /Q lintResult.txt | |
php -l %~1 >lintResult.txt 2>NUL | |
type lintResult.txt | findstr /C:"Deprecated" >NUL 2>NUL | |
if %errorlevel% EQU 0 ( | |
echo DEPRECATIONS: %~1 | |
SET n_some=0 | |
) | |
type lintResult.txt | findstr /C:"No syntax errors detected" >NUL 2>NUL | |
if %errorlevel% NEQ 0 ( | |
echo [101;97m SYNTAX ERRORS [0m %~1 | |
SET n_some=1 | |
EXIT /B 1 | |
) ELSE ( | |
EXIT /B 0 | |
) | |
:DONE | |
echo Done. | |
if "%n_some%"=="1" echo You can do "php -l \path\to\file.php" to see verbose errors/deprecations". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is useful for migrations to newer PHP versions: it checks all php files under the given path, including subdirectories, using "php -l"
It will display if there are deprecations and/or syntax errors, and will abort (stop checking) as soon some file has syntax errors.