From cbd4d75c22b01d69d4f2c83d66591133557ac38e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 4 Dec 2023 11:11:14 +0100 Subject: [PATCH] Fix php-cs-fixer for PHP 7.1 --- .php-cs-fixer.dist.php | 19 +++++++- dev/tools/php-cs-fixer/.gitignore | 2 + dev/tools/php-cs-fixer/run-php-cs-fixer.sh | 50 ++++++++++++++++------ 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index c5135d3dab5..ed371e20231 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,5 +1,19 @@ in(__DIR__) +->exclude([ + 'custom', + 'documents', + 'htdocs/custom', + 'htdocs/includes', +]) +->notPath('vendor'); + + +/* PHP 7.4+ */ +/* $finder = (new PhpCsFixer\Finder()) ->in(__DIR__) ->exclude([ @@ -10,8 +24,8 @@ $finder = (new PhpCsFixer\Finder()) ]) ->notPath([ 'vendor', - ]) -; + ]); +*/ return (new PhpCsFixer\Config()) ->setRules([ @@ -28,6 +42,7 @@ return (new PhpCsFixer\Config()) //'strict_param' => true, //'array_syntax' => ['syntax' => 'short'], //'list_syntax' => false, + //'visibility_required' => false, 'array_syntax' => false, 'ternary_to_null_coalescing' => false ]) diff --git a/dev/tools/php-cs-fixer/.gitignore b/dev/tools/php-cs-fixer/.gitignore index 57872d0f1e5..afb52232818 100644 --- a/dev/tools/php-cs-fixer/.gitignore +++ b/dev/tools/php-cs-fixer/.gitignore @@ -1 +1,3 @@ /vendor/ +/composer.json +/composer.lock diff --git a/dev/tools/php-cs-fixer/run-php-cs-fixer.sh b/dev/tools/php-cs-fixer/run-php-cs-fixer.sh index 96a3b69cd8f..b62befcf011 100755 --- a/dev/tools/php-cs-fixer/run-php-cs-fixer.sh +++ b/dev/tools/php-cs-fixer/run-php-cs-fixer.sh @@ -6,7 +6,7 @@ # Optionally set COMPOSER_VENDOR_DIR to your vendor path for composer. # # Run php-cs-fixer by calling this script: -# ./run-php-cs-fixer.sh check # Only checks +# ./run-php-cs-fixer.sh check # Only checks (not available with PHP 7.0) # ./run-php-cs-fixer.sh fix # Fixes # # You can fix only a few files using @@ -19,7 +19,7 @@ # COMPOSER_CMD="php ~/composer.phar" COMPOSER_VENDOR_DIR="~/vendor" ./run-php-cs-fixer.sh # # or export them: -# export COMPOSER_CMD="php ~/composer.phar" +# export COMPOSER_CMD="~/composer.phar" # export COMPOSER_VENDOR_DIR="~/vendor" # ./run-php-cs-fixer.sh # @@ -29,30 +29,52 @@ MYDIR=$(dirname "$(realpath "$0")") export COMPOSER_VENDOR_DIR=${COMPOSER_VENDOR_DIR:=$MYDIR/vendor} -COMPOSER_CMD=${COMPOSER_CMD:=composer} +COMPOSER_CMD=${COMPOSER_CMD:composer} +MINPHPVERSION="7.0" -# -# Install/update -# -PHP_CS_FIXER="${COMPOSER_VENDOR_DIR}/bin/php-cs-fixer" -if [ ! -r "${PHP_CS_FIXER}" ] ; then - [[ ! -e "${COMPOSER_VENDOR_DIR}" ]] && ${COMPOSER_CMD} install - [[ -e "${COMPOSER_VENDOR_DIR}" ]] && ${COMPOSER_CMD} update - ${COMPOSER_CMD} require --dev friendsofphp/php-cs-fixer -fi +echo "***** run-php-cs-fixer.sh *****" if [ "x$1" = "x" ]; then - echo "***** run-php-cs-fixer.sh *****" echo "Syntax: run-php-cs-fixer.sh check|fix [path]" exit 1; fi + +# +# Check composer is available +# +if [ ! -r "${COMPOSER_CMD}" ] ; then + echo composer is not available or not in path. You can give the path of composer by setting COMPOSER_CMD=/pathto/composer + echo Example: export COMPOSER_CMD="~/composer.phar" + echo Example: export COMPOSER_CMD="/usr/local/bin/composer" + exit 1; +fi + + +# +# Install/update php-cs-fixer +# +echo Install php-cs-fixer +PHP_CS_FIXER="${COMPOSER_VENDOR_DIR}/bin/php-cs-fixer" +if [ ! -r "${PHP_CS_FIXER}" ] ; then + [[ ! -e "${COMPOSER_VENDOR_DIR}" ]] && ${COMPOSER_CMD} install + [[ -e "${COMPOSER_VENDOR_DIR}" ]] && ${COMPOSER_CMD} update + php${MINPHPVERSION} ${COMPOSER_CMD} require --dev friendsofphp/php-cs-fixer + echo +fi + + +# With PHP 7.0, php-cs-fixer is V2 (command check not supported) +# With PHP 8.2, php-cs-fixer is V3 + ( + echo cd "${MYDIR}/../../.." cd "${MYDIR}/../../.." || exit CMD= # If no argument, run check by default [[ "$1" == "" ]] && CMD=check # shellcheck disable=SC2086 - "${PHP_CS_FIXER}" $CMD "$@" + echo php${MINPHPVERSION} "${PHP_CS_FIXER}" $CMD "$@" + php${MINPHPVERSION} "${PHP_CS_FIXER}" $CMD "$@" )