Browse Source

Fix php-cs-fixer for PHP 7.1

Laurent Destailleur 1 year ago
parent
commit
cbd4d75c22

+ 17 - 2
.php-cs-fixer.dist.php

@@ -1,5 +1,19 @@
 <?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())
 	->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
 	])

+ 2 - 0
dev/tools/php-cs-fixer/.gitignore

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

+ 34 - 12
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"
+
+
+echo "***** run-php-cs-fixer.sh *****"
+
+if [ "x$1" = "x" ]; then
+	echo "Syntax: run-php-cs-fixer.sh check|fix  [path]"
+	exit 1;
+fi
+
 
 #
-# Install/update
+# 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
-  ${COMPOSER_CMD} require --dev friendsofphp/php-cs-fixer
+  php${MINPHPVERSION} ${COMPOSER_CMD} require --dev friendsofphp/php-cs-fixer
+  echo
 fi
 
 
-if [ "x$1" = "x" ]; then
-	echo "***** run-php-cs-fixer.sh *****"
-	echo "Syntax: run-php-cs-fixer.sh check|fix  [path]"
-	exit 1;
-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 "$@"
 )