2
0
forked from Wavyzz/dolibarr

Fix php-cs-fixer for PHP 7.1

This commit is contained in:
Laurent Destailleur
2023-12-04 11:11:14 +01:00
parent 085f6e26f3
commit cbd4d75c22
3 changed files with 55 additions and 16 deletions

View File

@@ -1,5 +1,19 @@
<?php <?php
/* PHP 7.0 */
$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude([
'custom',
'documents',
'htdocs/custom',
'htdocs/includes',
])
->notPath('vendor');
/* PHP 7.4+ */
/*
$finder = (new PhpCsFixer\Finder()) $finder = (new PhpCsFixer\Finder())
->in(__DIR__) ->in(__DIR__)
->exclude([ ->exclude([
@@ -10,8 +24,8 @@ $finder = (new PhpCsFixer\Finder())
]) ])
->notPath([ ->notPath([
'vendor', 'vendor',
]) ]);
; */
return (new PhpCsFixer\Config()) return (new PhpCsFixer\Config())
->setRules([ ->setRules([
@@ -28,6 +42,7 @@ return (new PhpCsFixer\Config())
//'strict_param' => true, //'strict_param' => true,
//'array_syntax' => ['syntax' => 'short'], //'array_syntax' => ['syntax' => 'short'],
//'list_syntax' => false, //'list_syntax' => false,
//'visibility_required' => false,
'array_syntax' => false, 'array_syntax' => false,
'ternary_to_null_coalescing' => false 'ternary_to_null_coalescing' => false
]) ])

View File

@@ -1 +1,3 @@
/vendor/ /vendor/
/composer.json
/composer.lock

View File

@@ -6,7 +6,7 @@
# Optionally set COMPOSER_VENDOR_DIR to your vendor path for composer. # Optionally set COMPOSER_VENDOR_DIR to your vendor path for composer.
# #
# Run php-cs-fixer by calling this script: # 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 # ./run-php-cs-fixer.sh fix # Fixes
# #
# You can fix only a few files using # 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 # COMPOSER_CMD="php ~/composer.phar" COMPOSER_VENDOR_DIR="~/vendor" ./run-php-cs-fixer.sh
# #
# or export them: # or export them:
# export COMPOSER_CMD="php ~/composer.phar" # export COMPOSER_CMD="~/composer.phar"
# export COMPOSER_VENDOR_DIR="~/vendor" # export COMPOSER_VENDOR_DIR="~/vendor"
# ./run-php-cs-fixer.sh # ./run-php-cs-fixer.sh
# #
@@ -29,30 +29,52 @@
MYDIR=$(dirname "$(realpath "$0")") MYDIR=$(dirname "$(realpath "$0")")
export COMPOSER_VENDOR_DIR=${COMPOSER_VENDOR_DIR:=$MYDIR/vendor} 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 if [ "x$1" = "x" ]; then
echo "***** run-php-cs-fixer.sh *****"
echo "Syntax: run-php-cs-fixer.sh check|fix [path]" echo "Syntax: run-php-cs-fixer.sh check|fix [path]"
exit 1; exit 1;
fi 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 cd "${MYDIR}/../../.." || exit
CMD= CMD=
# If no argument, run check by default # If no argument, run check by default
[[ "$1" == "" ]] && CMD=check [[ "$1" == "" ]] && CMD=check
# shellcheck disable=SC2086 # shellcheck disable=SC2086
"${PHP_CS_FIXER}" $CMD "$@" echo php${MINPHPVERSION} "${PHP_CS_FIXER}" $CMD "$@"
php${MINPHPVERSION} "${PHP_CS_FIXER}" $CMD "$@"
) )