diff --git a/rector.php b/rector.php index c3547b82f596..cd5f3c21dd0f 100644 --- a/rector.php +++ b/rector.php @@ -25,6 +25,7 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; use Rector\DeadCode\Rector\MethodCall\RemoveNullArgOnNullDefaultParamRector; +use Rector\DeadCode\Rector\Property\RemoveDefaultValueFromAssignedPropertyRector; use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector; use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; @@ -33,6 +34,7 @@ use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector; use Rector\PHPUnit\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector; use Rector\PHPUnit\CodeQuality\Rector\StmtsAwareInterface\DeclareStrictTypesTestsRector; @@ -102,6 +104,16 @@ __DIR__ . '/system/HTTP/Response.php', ], + // Keep property defaults for backward compatibility. + RemoveDefaultValueFromAssignedPropertyRector::class, + + ReadOnlyPropertyRector::class => [ + __DIR__ . '/system/Cache/ResponseCache.php', + __DIR__ . '/system/HotReloader/IteratorFilter.php', + __DIR__ . '/system/Router/RouteCollection.php', + __DIR__ . '/system/Security/Security.php', + ], + // Exclude test file because `is_cli()` is mocked and Rector might remove needed parameters. RemoveExtraParametersRector::class => [ __DIR__ . '/tests/system/Debug/ToolbarTest.php', diff --git a/system/Config/Services.php b/system/Config/Services.php index cef65a8895a9..35db6c57241a 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -343,7 +343,6 @@ public static function image(?string $handler = null, ?Images $config = null, bo } $config ??= config(Images::class); - assert($config instanceof Images); $handler = in_array($handler, [null, '', '0'], true) ? $config->defaultHandler : $handler; $class = $config->handlers[$handler]; diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 3c08958604d2..8253973beb27 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -1335,7 +1335,7 @@ protected function fillRouteParams(string $from, ?array $params = null): string // Ensure that the param we're inserting matches // the expected param type. - $pos = strpos($from, $pattern); + $pos = strpos($from, (string) $pattern); $from = substr_replace($from, $params[$index], $pos, strlen($pattern)); } @@ -1397,7 +1397,7 @@ protected function buildReverseRoute(string $from, array $params): string // Ensure that the param we're inserting matches // the expected param type. - $pos = strpos($from, $placeholder); + $pos = strpos($from, (string) $placeholder); $from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder)); } diff --git a/tests/system/AutoReview/FrameworkCodeTest.php b/tests/system/AutoReview/FrameworkCodeTest.php index de515fffebf6..7345b5dfa537 100644 --- a/tests/system/AutoReview/FrameworkCodeTest.php +++ b/tests/system/AutoReview/FrameworkCodeTest.php @@ -62,7 +62,6 @@ public function testEachTestClassHasCorrectGroupAttributeName(string $class): vo $unrecognizedGroups = array_diff( array_map(static function (ReflectionAttribute $attribute): string { $groupAttribute = $attribute->newInstance(); - assert($groupAttribute instanceof Group); return $groupAttribute->name(); }, $attributes), diff --git a/tests/system/Database/Live/GetNumRowsTest.php b/tests/system/Database/Live/GetNumRowsTest.php index c7575462d598..302b1e313695 100644 --- a/tests/system/Database/Live/GetNumRowsTest.php +++ b/tests/system/Database/Live/GetNumRowsTest.php @@ -29,28 +29,6 @@ final class GetNumRowsTest extends CIUnitTestCase protected $refresh = true; protected $seed = CITestSeeder::class; - /** - * Added as instructed at https://codeigniter4.github.io/userguide/testing/database.html#the-test-class - * {@inheritDoc} - * - * @see \CodeIgniter\Test\CIDatabaseTestCase::setUp() - */ - protected function setUp(): void - { - parent::setUp(); - } - - /** - * Added as instructed at https://codeigniter4.github.io/userguide/testing/database.html#the-test-class - * {@inheritDoc} - * - * @see \CodeIgniter\Test\CIDatabaseTestCase::tearDown() - */ - protected function tearDown(): void - { - parent::tearDown(); - } - /** * tests newly added ResultInterface::getNumRows with a live db */ diff --git a/tests/system/Database/Migrations/MigrationTest.php b/tests/system/Database/Migrations/MigrationTest.php index 7e4049a113ce..90d71db35c15 100644 --- a/tests/system/Database/Migrations/MigrationTest.php +++ b/tests/system/Database/Migrations/MigrationTest.php @@ -26,11 +26,6 @@ final class MigrationTest extends CIUnitTestCase { use DatabaseTestTrait; - protected function setUp(): void - { - parent::setUp(); - } - public function testDBGroup(): void { $migration = new class () extends Migration { diff --git a/tests/system/Models/GeneralModelTest.php b/tests/system/Models/GeneralModelTest.php index c0d3d806dbdd..9bc62c2d3501 100644 --- a/tests/system/Models/GeneralModelTest.php +++ b/tests/system/Models/GeneralModelTest.php @@ -35,11 +35,6 @@ final class GeneralModelTest extends CIUnitTestCase */ private ?object $model = null; - protected function setUp(): void - { - parent::setUp(); - } - protected function tearDown(): void { parent::tearDown(); diff --git a/tests/system/Models/LiveModelTestCase.php b/tests/system/Models/LiveModelTestCase.php index 342daecdf302..31b2af8edbca 100644 --- a/tests/system/Models/LiveModelTestCase.php +++ b/tests/system/Models/LiveModelTestCase.php @@ -38,11 +38,6 @@ abstract class LiveModelTestCase extends CIUnitTestCase protected $seed = CITestSeeder::class; - protected function setUp(): void - { - parent::setUp(); - } - protected function tearDown(): void { parent::tearDown(); diff --git a/tests/system/Test/TestResponseTest.php b/tests/system/Test/TestResponseTest.php index dc175897b870..315e1f8db6bd 100644 --- a/tests/system/Test/TestResponseTest.php +++ b/tests/system/Test/TestResponseTest.php @@ -29,11 +29,6 @@ final class TestResponseTest extends CIUnitTestCase private ?TestResponse $testResponse = null; private Response $response; - protected function setUp(): void - { - parent::setUp(); - } - #[DataProvider('provideHttpStatusCodes')] public function testIsOK(int $code, bool $isOk): void { diff --git a/utils/phpstan-baseline/empty.notAllowed.neon b/utils/phpstan-baseline/empty.notAllowed.neon index 827126f98676..796292761d9c 100644 --- a/utils/phpstan-baseline/empty.notAllowed.neon +++ b/utils/phpstan-baseline/empty.notAllowed.neon @@ -1,4 +1,4 @@ -# total 212 errors +# total 205 errors parameters: ignoreErrors: diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 5214bfa1141b..03e4965a51a4 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 1819 errors +# total 1810 errors includes: - argument.type.neon @@ -16,7 +16,6 @@ includes: - missingType.parameter.neon - missingType.property.neon - nullCoalesce.property.neon - - offsetAccess.notFound.neon - property.defaultValue.neon - property.nonObject.neon - property.notFound.neon diff --git a/utils/phpstan-baseline/offsetAccess.notFound.neon b/utils/phpstan-baseline/offsetAccess.notFound.neon deleted file mode 100644 index ba50b4d14f96..000000000000 --- a/utils/phpstan-baseline/offsetAccess.notFound.neon +++ /dev/null @@ -1,8 +0,0 @@ -# total 2 errors - -parameters: - ignoreErrors: - - - message: '#^Offset ''_ci_old_input'' does not exist on array\{\}\.$#' - count: 2 - path: ../../tests/system/HTTP/RedirectResponseTest.php