From 00c7086d7d380d9be31c5f808df5cc37ab793218 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 18 Jul 2023 17:25:10 +0800 Subject: [PATCH] Adjust registering of custom fixers for PHP 8.0+ only --- .php-cs-fixer.dist.php | 21 ++++++++++++++------- .php-cs-fixer.no-header.php | 21 ++++++++++++++------- .php-cs-fixer.user-guide.php | 21 ++++++++++++++------- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index b2f86c686252..3653cf1349c2 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -46,16 +46,23 @@ $overrides = []; $options = [ - 'cacheFile' => 'build/.php-cs-fixer.cache', - 'finder' => $finder, - 'customFixers' => FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer'), - 'customRules' => [ - NoCodeSeparatorCommentFixer::name() => true, - ], + 'cacheFile' => 'build/.php-cs-fixer.cache', + 'finder' => $finder, ]; -return Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary( +$config = Factory::create(new CodeIgniter4(), $overrides, $options)->forLibrary( 'CodeIgniter 4 framework', 'CodeIgniter Foundation', 'admin@codeigniter.com' ); + +// @TODO: remove this check when support for PHP 7.4 is dropped +if (PHP_VERSION_ID >= 80000) { + $config + ->registerCustomFixers(FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer')) + ->setRules(array_merge($config->getRules(), [ + NoCodeSeparatorCommentFixer::name() => true, + ])); +} + +return $config; diff --git a/.php-cs-fixer.no-header.php b/.php-cs-fixer.no-header.php index cd10717aa5a2..7c9ae1e80737 100644 --- a/.php-cs-fixer.no-header.php +++ b/.php-cs-fixer.no-header.php @@ -32,12 +32,19 @@ $overrides = []; $options = [ - 'cacheFile' => 'build/.php-cs-fixer.no-header.cache', - 'finder' => $finder, - 'customFixers' => FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer'), - 'customRules' => [ - NoCodeSeparatorCommentFixer::name() => true, - ], + 'cacheFile' => 'build/.php-cs-fixer.no-header.cache', + 'finder' => $finder, ]; -return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects(); +$config = Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects(); + +// @TODO: remove this check when support for PHP 7.4 is dropped +if (PHP_VERSION_ID >= 80000) { + $config + ->registerCustomFixers(FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer')) + ->setRules(array_merge($config->getRules(), [ + NoCodeSeparatorCommentFixer::name() => true, + ])); +} + +return $config; diff --git a/.php-cs-fixer.user-guide.php b/.php-cs-fixer.user-guide.php index 1fa41bc4fb42..a3ae78a48232 100644 --- a/.php-cs-fixer.user-guide.php +++ b/.php-cs-fixer.user-guide.php @@ -36,12 +36,19 @@ ]; $options = [ - 'cacheFile' => 'build/.php-cs-fixer.user-guide.cache', - 'finder' => $finder, - 'customFixers' => FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer'), - 'customRules' => [ - NoCodeSeparatorCommentFixer::name() => true, - ], + 'cacheFile' => 'build/.php-cs-fixer.no-header.cache', + 'finder' => $finder, ]; -return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects(); +$config = Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects(); + +// @TODO: remove this check when support for PHP 7.4 is dropped +if (PHP_VERSION_ID >= 80000) { + $config + ->registerCustomFixers(FixerGenerator::create('vendor/nexusphp/cs-config/src/Fixer', 'Nexus\\CsConfig\\Fixer')) + ->setRules(array_merge($config->getRules(), [ + NoCodeSeparatorCommentFixer::name() => true, + ])); +} + +return $config;