From 25e3a74e1c5981967f3d1374f707457273057cc8 Mon Sep 17 00:00:00 2001 From: justbyitself <160424955+justbyitself@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:25:55 +0100 Subject: [PATCH 1/3] refactor: Replace PHP_VERSION by PHP_VERSION_ID PHP_VERSION_ID is prefered at CodeIgniter4 repository. --- system/Autoloader/Autoloader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 2f9b13c0b818..99c7079edcd2 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -346,7 +346,7 @@ public function sanitizeFilename(string $filename): string ); } if ($result === false) { - if (version_compare(PHP_VERSION, '8.0.0', '>=')) { + if (PHP_VERSION_ID >= 80000) { $message = preg_last_error_msg(); } else { $message = 'Regex error. error code: ' . preg_last_error(); From 6bcd1011e755675d9294efbf8f35545a8704ab94 Mon Sep 17 00:00:00 2001 From: justbyitself <160424955+justbyitself@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:16:34 +0100 Subject: [PATCH 2/3] chore: add version-compare-func-call-to-constant rule Add Rector rule in order to replace PHP_VERSION by PHP_VERSION_ID. @samsonasik suggestion: https://github.com/codeigniter4/CodeIgniter4/pull/8619 --- rector.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rector.php b/rector.php index 6ee2738f2618..2c888f0c80ea 100644 --- a/rector.php +++ b/rector.php @@ -18,6 +18,7 @@ use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector; use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector; use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector; +use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector; use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; use Rector\CodeQuality\Rector\If_\CombineIfRector; use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; @@ -149,6 +150,7 @@ $rectorConfig->rule(CompleteDynamicPropertiesRector::class); $rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class); $rectorConfig->rule(SingleInArrayToCompareRector::class); + $rectorConfig->rule(VersionCompareFuncCallToConstantRector::class); $rectorConfig ->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [ From f3e53914b770a243da86890427d08cb1c6f41e70 Mon Sep 17 00:00:00 2001 From: justbyitself Date: Mon, 11 Mar 2024 22:52:34 +0100 Subject: [PATCH 3/3] refactor: apply cs-fix and rector --- rector.php | 2 +- system/Autoloader/Autoloader.php | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/rector.php b/rector.php index 2c888f0c80ea..5e19e8e01413 100644 --- a/rector.php +++ b/rector.php @@ -18,7 +18,6 @@ use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector; use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector; use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector; -use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector; use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; use Rector\CodeQuality\Rector\If_\CombineIfRector; use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; @@ -29,6 +28,7 @@ use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; +use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector; use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 99c7079edcd2..088c850efa58 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -346,11 +346,7 @@ public function sanitizeFilename(string $filename): string ); } if ($result === false) { - if (PHP_VERSION_ID >= 80000) { - $message = preg_last_error_msg(); - } else { - $message = 'Regex error. error code: ' . preg_last_error(); - } + $message = PHP_VERSION_ID >= 80000 ? preg_last_error_msg() : 'Regex error. error code: ' . preg_last_error(); throw new RuntimeException($message . '. filename: "' . $filename . '"'); }