diff --git a/composer.json b/composer.json index 3163236ad3c3..ff8aee6027c4 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "phpunit/phpcov": "^9.0.2 || ^10.0", "phpunit/phpunit": "^10.5.16 || ^11.2", "predis/predis": "^3.0", - "rector/rector": "2.2.3", + "rector/rector": "2.2.4", "shipmonk/phpstan-baseline-per-identifier": "^2.0" }, "replace": { diff --git a/rector.php b/rector.php index dea282d17bef..f2aed4ac2969 100644 --- a/rector.php +++ b/rector.php @@ -21,6 +21,7 @@ use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector; +use Rector\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector; use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; @@ -37,7 +38,6 @@ use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; -use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector; use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; @@ -52,7 +52,7 @@ return RectorConfig::configure() ->withPhpSets(php81: true) - ->withPreparedSets(deadCode: true, instanceOf: true, strictBooleans: true, phpunitCodeQuality: true) + ->withPreparedSets(deadCode: true, instanceOf: true, phpunitCodeQuality: true) ->withComposerBased(phpunit: true) ->withParallel(120, 8, 10) ->withCache( @@ -169,6 +169,9 @@ // possibly isset() on purpose, on updated Config classes property accross versions IssetOnPropertyObjectToPropertyExistsRector::class, + + // needs separate PR for activation to allow more depth review + FunctionLikeToFirstClassCallableRector::class, ]) // auto import fully qualified class names ->withImportNames(removeUnusedImports: true) @@ -189,7 +192,6 @@ TernaryEmptyArrayArrayDimFetchToCoalesceRector::class, DisallowedEmptyRuleFixerRector::class, PrivatizeFinalClassPropertyRector::class, - BooleanInIfConditionRuleFixerRector::class, VersionCompareFuncCallToConstantRector::class, AddClosureVoidReturnTypeWhereNoReturnRector::class, AddFunctionVoidReturnTypeWhereNoReturnRector::class, diff --git a/system/Config/Services.php b/system/Config/Services.php index c9266a892e38..c2a73f839f28 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -345,7 +345,7 @@ public static function image(?string $handler = null, ?Images $config = null, bo $config ??= config(Images::class); assert($config instanceof Images); - $handler = $handler !== null && $handler !== '' && $handler !== '0' ? $handler : $config->defaultHandler; + $handler = in_array($handler, [null, '', '0'], true) ? $config->defaultHandler : $handler; $class = $config->handlers[$handler]; return new $class($config); @@ -385,7 +385,7 @@ public static function language(?string $locale = null, bool $getShared = true) } // Use '?:' for empty string check - $locale = $locale !== null && $locale !== '' && $locale !== '0' ? $locale : $requestLocale; + $locale = in_array($locale, [null, '', '0'], true) ? $requestLocale : $locale; return new Language($locale); } @@ -484,7 +484,7 @@ public static function parser(?string $viewPath = null, ?ViewConfig $config = nu return static::getSharedInstance('parser', $viewPath, $config); } - $viewPath = $viewPath !== null && $viewPath !== '' && $viewPath !== '0' ? $viewPath : (new Paths())->viewDirectory; + $viewPath = in_array($viewPath, [null, '', '0'], true) ? (new Paths())->viewDirectory : $viewPath; $config ??= config(ViewConfig::class); return new Parser($config, $viewPath, AppServices::get('locator'), CI_DEBUG, AppServices::get('logger')); @@ -503,7 +503,7 @@ public static function renderer(?string $viewPath = null, ?ViewConfig $config = return static::getSharedInstance('renderer', $viewPath, $config); } - $viewPath = $viewPath !== null && $viewPath !== '' && $viewPath !== '0' ? $viewPath : (new Paths())->viewDirectory; + $viewPath = in_array($viewPath, [null, '', '0'], true) ? (new Paths())->viewDirectory : $viewPath; $config ??= config(ViewConfig::class); return new View($config, $viewPath, AppServices::get('locator'), CI_DEBUG, AppServices::get('logger')); diff --git a/system/Cookie/Cookie.php b/system/Cookie/Cookie.php index a966c8fceee8..e3d2488e6a10 100644 --- a/system/Cookie/Cookie.php +++ b/system/Cookie/Cookie.php @@ -507,7 +507,7 @@ public function withExpired() */ public function withPath(?string $path) { - $path = $path !== null && $path !== '' && $path !== '0' ? $path : self::$defaults['path']; + $path = in_array($path, [null, '', '0'], true) ? self::$defaults['path'] : $path; $this->validatePrefix($this->prefix, $this->secure, $path, $this->domain); $cookie = clone $this; diff --git a/system/I18n/TimeTrait.php b/system/I18n/TimeTrait.php index 42278c960c43..7742c73a65ac 100644 --- a/system/I18n/TimeTrait.php +++ b/system/I18n/TimeTrait.php @@ -73,7 +73,7 @@ trait TimeTrait */ public function __construct(?string $time = null, $timezone = null, ?string $locale = null) { - $this->locale = $locale !== null && $locale !== '' && $locale !== '0' ? $locale : Locale::getDefault(); + $this->locale = in_array($locale, [null, '', '0'], true) ? Locale::getDefault() : $locale; $time ??= ''; @@ -940,7 +940,7 @@ public function sameAs($testTime, ?string $timezone = null): bool if ($testTime instanceof DateTimeInterface) { $testTime = $testTime->format('Y-m-d H:i:s.u O'); } elseif (is_string($testTime)) { - $timezone = $timezone !== null && $timezone !== '' && $timezone !== '0' ? $timezone : $this->timezone; + $timezone = in_array($timezone, [null, '', '0'], true) ? $this->timezone : $timezone; $timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); $testTime = new DateTime($testTime, $timezone); $testTime = $testTime->format('Y-m-d H:i:s.u O'); @@ -1102,7 +1102,7 @@ public function getUTCObject($time, ?string $timezone = null) if ($time instanceof static) { $time = $time->toDateTime(); } elseif (is_string($time)) { - $timezone = $timezone !== null && $timezone !== '' && $timezone !== '0' ? $timezone : $this->timezone; + $timezone = in_array($timezone, [null, '', '0'], true) ? $this->timezone : $timezone; $timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); $time = new DateTime($time, $timezone); } diff --git a/system/View/Cell.php b/system/View/Cell.php index ccf24cbca210..3a3e9595e3f5 100644 --- a/system/View/Cell.php +++ b/system/View/Cell.php @@ -154,10 +154,6 @@ public function prepareParams($params) unset($newParams); } - if ($params === []) { - return []; - } - return $params; }