diff --git a/composer.json b/composer.json index 6f15a3622b7a..9de4dacdf72f 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "phpunit/phpcov": "^9.0.2 || ^10.0", "phpunit/phpunit": "^10.5.16 || ^11.2", "predis/predis": "^3.0", - "rector/rector": "2.4.6", + "rector/rector": "2.5.2", "shipmonk/phpstan-baseline-per-identifier": "^2.0" }, "replace": { diff --git a/rector.php b/rector.php index 4552a898aee3..cfcbbd236bad 100644 --- a/rector.php +++ b/rector.php @@ -24,20 +24,19 @@ use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; -use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector; use Rector\DeadCode\Rector\MethodCall\RemoveNullArgOnNullDefaultParamRector; use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector; use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector; use Rector\Php70\Rector\FuncCall\RandomFunctionRector; -use Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector; use Rector\PHPUnit\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector; use Rector\PHPUnit\CodeQuality\Rector\StmtsAwareInterface\DeclareStrictTypesTestsRector; +use Rector\PostRector\Rector\UnusedImportRemovingPostRector; use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\Renaming\Rector\ConstFetch\RenameConstantRector; @@ -96,17 +95,10 @@ RemoveUnusedPrivateMethodRector::class => [ // private method called via getPrivateMethodInvoker - __DIR__ . '/tests/system/Test/ReflectionHelperTest.php', __DIR__ . '/tests/_support/Test/TestForReflectionHelper.php', ], RemoveUnusedConstructorParamRector::class => [ - // there are deprecated parameters - __DIR__ . '/system/Debug/Exceptions.php', - // @TODO remove if deprecated $httpVerb is removed - __DIR__ . '/system/Router/AutoRouterImproved.php', - // @TODO remove if deprecated $config is removed - __DIR__ . '/system/HTTP/Request.php', __DIR__ . '/system/HTTP/Response.php', ], @@ -115,11 +107,6 @@ __DIR__ . '/tests/system/Debug/ToolbarTest.php', ], - // check on constant compare - UnwrapFutureCompatibleIfPhpVersionRector::class => [ - __DIR__ . '/system/Autoloader/Autoloader.php', - ], - UnderscoreToCamelCaseVariableNameRector::class => [ // session handlers have the gc() method with underscored parameter `$max_lifetime` __DIR__ . '/system/Session/Handlers', @@ -130,10 +117,7 @@ __DIR__ . '/app', __DIR__ . '/system/CodeIgniter.php', __DIR__ . '/system/Config/BaseConfig.php', - __DIR__ . '/system/Commands/Generators/Views', - __DIR__ . '/system/Pager/Views', __DIR__ . '/system/Test/ControllerTestTrait.php', - __DIR__ . '/system/Validation/Views', __DIR__ . '/system/View/Parser.php', __DIR__ . '/tests/system/Debug/ExceptionsTest.php', ], @@ -149,15 +133,11 @@ __DIR__ . '/system/Filters/Filters.php', __DIR__ . '/system/HTTP/CURLRequest.php', __DIR__ . '/system/HTTP/DownloadResponse.php', - __DIR__ . '/system/HTTP/IncomingRequest.php', __DIR__ . '/system/Security/Security.php', __DIR__ . '/system/Session/Session.php', ], ReturnNeverTypeRector::class => [ - __DIR__ . '/system/Cache/Handlers/BaseHandler.php', - __DIR__ . '/system/Cache/Handlers/MemcachedHandler.php', - __DIR__ . '/system/Cache/Handlers/WincacheHandler.php', __DIR__ . '/system/CodeIgniter.php', __DIR__ . '/system/Database/MySQLi/Utils.php', __DIR__ . '/system/Database/OCI8/Utils.php', @@ -166,8 +146,6 @@ __DIR__ . '/system/Database/SQLite3/Utils.php', __DIR__ . '/system/HTTP/DownloadResponse.php', __DIR__ . '/system/HTTP/SiteURI.php', - __DIR__ . '/system/Helpers/kint_helper.php', - __DIR__ . '/tests/_support/Autoloader/FatalLocator.php', ], // Unnecessary (string) is inserted @@ -197,12 +175,13 @@ __DIR__ . '/tests/system/Models', ], - StaticCallOnNonStaticToInstanceCallRector::class => [ - __DIR__ . '/tests/_support/Config/Services.php', + UnusedImportRemovingPostRector::class => [ + // buggy on auto import removed + __DIR__ . '/system/HTTP/Response.php', ], ]) // auto import fully qualified class names - ->withImportNames(removeUnusedImports: true) + ->withImportNames() ->withRules([ DeclareStrictTypesRector::class, UnderscoreToCamelCaseVariableNameRector::class, @@ -231,4 +210,5 @@ ->withConfiguredRule(RenameConstantRector::class, [ 'FILTER_DEFAULT' => 'FILTER_UNSAFE_RAW', ]) - ->withCodeQualityLevel(61); + ->withCodeQualityLevel(61) + ->reportUnusedSkips(); diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 9cdbbbada0b5..d26681213914 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -1012,7 +1012,7 @@ public static function getOptionString(bool $useLongOpts = false, bool $trim = f continue; } - if (mb_strpos($value, ' ') !== false) { + if (str_contains($value, ' ')) { $out .= "\"{$value}\" "; } elseif ($value !== null) { $out .= "{$value} "; diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php index bde4e1b8e3f8..453272a4f59a 100644 --- a/system/HTTP/CLIRequest.php +++ b/system/HTTP/CLIRequest.php @@ -164,7 +164,7 @@ public function getOptionString(bool $useLongOpts = false): string continue; } - if (mb_strpos($value, ' ') !== false) { + if (str_contains($value, ' ')) { $out .= '"' . $value . '" '; } else { $out .= "{$value} "; diff --git a/system/Test/DOMParser.php b/system/Test/DOMParser.php index d8521edfbc86..52765a4d656b 100644 --- a/system/Test/DOMParser.php +++ b/system/Test/DOMParser.php @@ -112,7 +112,7 @@ public function see(?string $search = null, ?string $element = null): bool if ($element === null) { $content = $this->dom->saveHTML($this->dom->documentElement); - return mb_strpos($content, $search) !== false; + return str_contains($content, $search); } $result = $this->doXPath($search, $element);