Skip to content

Commit 55f9876

Browse files
authored
chore: update PHPStan baseline and Rector config (#10431)
* fix phpstan * fix rector
1 parent 977c8d7 commit 55f9876

12 files changed

Lines changed: 16 additions & 57 deletions

File tree

rector.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
2626
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
2727
use Rector\DeadCode\Rector\MethodCall\RemoveNullArgOnNullDefaultParamRector;
28+
use Rector\DeadCode\Rector\Property\RemoveDefaultValueFromAssignedPropertyRector;
2829
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
2930
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
3031
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
@@ -33,6 +34,7 @@
3334
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
3435
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
3536
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
37+
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
3638
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
3739
use Rector\PHPUnit\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector;
3840
use Rector\PHPUnit\CodeQuality\Rector\StmtsAwareInterface\DeclareStrictTypesTestsRector;
@@ -102,6 +104,16 @@
102104
__DIR__ . '/system/HTTP/Response.php',
103105
],
104106

107+
// Keep property defaults for backward compatibility.
108+
RemoveDefaultValueFromAssignedPropertyRector::class,
109+
110+
ReadOnlyPropertyRector::class => [
111+
__DIR__ . '/system/Cache/ResponseCache.php',
112+
__DIR__ . '/system/HotReloader/IteratorFilter.php',
113+
__DIR__ . '/system/Router/RouteCollection.php',
114+
__DIR__ . '/system/Security/Security.php',
115+
],
116+
105117
// Exclude test file because `is_cli()` is mocked and Rector might remove needed parameters.
106118
RemoveExtraParametersRector::class => [
107119
__DIR__ . '/tests/system/Debug/ToolbarTest.php',

system/Config/Services.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ public static function image(?string $handler = null, ?Images $config = null, bo
343343
}
344344

345345
$config ??= config(Images::class);
346-
assert($config instanceof Images);
347346

348347
$handler = in_array($handler, [null, '', '0'], true) ? $config->defaultHandler : $handler;
349348
$class = $config->handlers[$handler];

system/Router/RouteCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ protected function fillRouteParams(string $from, ?array $params = null): string
13351335

13361336
// Ensure that the param we're inserting matches
13371337
// the expected param type.
1338-
$pos = strpos($from, $pattern);
1338+
$pos = strpos($from, (string) $pattern);
13391339
$from = substr_replace($from, $params[$index], $pos, strlen($pattern));
13401340
}
13411341

@@ -1397,7 +1397,7 @@ protected function buildReverseRoute(string $from, array $params): string
13971397

13981398
// Ensure that the param we're inserting matches
13991399
// the expected param type.
1400-
$pos = strpos($from, $placeholder);
1400+
$pos = strpos($from, (string) $placeholder);
14011401
$from = substr_replace($from, (string) $params[$index], $pos, strlen($placeholder));
14021402
}
14031403

tests/system/AutoReview/FrameworkCodeTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function testEachTestClassHasCorrectGroupAttributeName(string $class): vo
6262
$unrecognizedGroups = array_diff(
6363
array_map(static function (ReflectionAttribute $attribute): string {
6464
$groupAttribute = $attribute->newInstance();
65-
assert($groupAttribute instanceof Group);
6665

6766
return $groupAttribute->name();
6867
}, $attributes),

tests/system/Database/Live/GetNumRowsTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,6 @@ final class GetNumRowsTest extends CIUnitTestCase
2929
protected $refresh = true;
3030
protected $seed = CITestSeeder::class;
3131

32-
/**
33-
* Added as instructed at https://codeigniter4.github.io/userguide/testing/database.html#the-test-class
34-
* {@inheritDoc}
35-
*
36-
* @see \CodeIgniter\Test\CIDatabaseTestCase::setUp()
37-
*/
38-
protected function setUp(): void
39-
{
40-
parent::setUp();
41-
}
42-
43-
/**
44-
* Added as instructed at https://codeigniter4.github.io/userguide/testing/database.html#the-test-class
45-
* {@inheritDoc}
46-
*
47-
* @see \CodeIgniter\Test\CIDatabaseTestCase::tearDown()
48-
*/
49-
protected function tearDown(): void
50-
{
51-
parent::tearDown();
52-
}
53-
5432
/**
5533
* tests newly added ResultInterface::getNumRows with a live db
5634
*/

tests/system/Database/Migrations/MigrationTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ final class MigrationTest extends CIUnitTestCase
2626
{
2727
use DatabaseTestTrait;
2828

29-
protected function setUp(): void
30-
{
31-
parent::setUp();
32-
}
33-
3429
public function testDBGroup(): void
3530
{
3631
$migration = new class () extends Migration {

tests/system/Models/GeneralModelTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ final class GeneralModelTest extends CIUnitTestCase
3535
*/
3636
private ?object $model = null;
3737

38-
protected function setUp(): void
39-
{
40-
parent::setUp();
41-
}
42-
4338
protected function tearDown(): void
4439
{
4540
parent::tearDown();

tests/system/Models/LiveModelTestCase.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ abstract class LiveModelTestCase extends CIUnitTestCase
3838

3939
protected $seed = CITestSeeder::class;
4040

41-
protected function setUp(): void
42-
{
43-
parent::setUp();
44-
}
45-
4641
protected function tearDown(): void
4742
{
4843
parent::tearDown();

tests/system/Test/TestResponseTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ final class TestResponseTest extends CIUnitTestCase
2929
private ?TestResponse $testResponse = null;
3030
private Response $response;
3131

32-
protected function setUp(): void
33-
{
34-
parent::setUp();
35-
}
36-
3732
#[DataProvider('provideHttpStatusCodes')]
3833
public function testIsOK(int $code, bool $isOk): void
3934
{

utils/phpstan-baseline/empty.notAllowed.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 212 errors
1+
# total 205 errors
22

33
parameters:
44
ignoreErrors:

0 commit comments

Comments
 (0)