Skip to content

Commit 87eb71c

Browse files
committed
refactor: enable AddMethodCallBasedStrictParamTypeRector
1 parent 655bd1d commit 87eb71c

File tree

7 files changed

+15
-33
lines changed

7 files changed

+15
-33
lines changed

phpstan-baseline.php

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@
14861486
$ignoreErrors[] = [
14871487
// identifier: empty.notAllowed
14881488
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
1489-
'count' => 30,
1489+
'count' => 29,
14901490
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
14911491
];
14921492
$ignoreErrors[] = [
@@ -1933,6 +1933,12 @@
19331933
'count' => 1,
19341934
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
19351935
];
1936+
$ignoreErrors[] = [
1937+
// identifier: isset.offset
1938+
'message' => '#^Offset 4 on array\\{string, string, string, string, string, string\\} in isset\\(\\) always exists and is not nullable\\.$#',
1939+
'count' => 1,
1940+
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
1941+
];
19361942
$ignoreErrors[] = [
19371943
// identifier: booleanNot.exprNotBoolean
19381944
'message' => '#^Only booleans are allowed in a negated boolean, TWhenNot given\\.$#',
@@ -11451,7 +11457,7 @@
1145111457
];
1145211458
$ignoreErrors[] = [
1145311459
// identifier: codeigniter.superglobalAccessAssign
11454-
'message' => '#^Assigning mixed directly on offset \'CONTENT_TYPE\' of \\$_SERVER is discouraged\\.$#',
11460+
'message' => '#^Assigning string directly on offset \'CONTENT_TYPE\' of \\$_SERVER is discouraged\\.$#',
1145511461
'count' => 1,
1145611462
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
1145711463
];
@@ -11485,18 +11491,6 @@
1148511491
'count' => 1,
1148611492
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
1148711493
];
11488-
$ignoreErrors[] = [
11489-
// identifier: missingType.parameter
11490-
'message' => '#^Method CodeIgniter\\\\API\\\\ResponseTraitTest\\:\\:tryValidContentType\\(\\) has parameter \\$contentType with no type specified\\.$#',
11491-
'count' => 1,
11492-
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
11493-
];
11494-
$ignoreErrors[] = [
11495-
// identifier: missingType.parameter
11496-
'message' => '#^Method CodeIgniter\\\\API\\\\ResponseTraitTest\\:\\:tryValidContentType\\(\\) has parameter \\$mimeType with no type specified\\.$#',
11497-
'count' => 1,
11498-
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
11499-
];
1150011494
$ignoreErrors[] = [
1150111495
// identifier: missingType.parameter
1150211496
'message' => '#^Method class@anonymous/tests/system/API/ResponseTraitTest\\.php\\:116\\:\\:__construct\\(\\) has parameter \\$formatter with no type specified\\.$#',
@@ -16765,12 +16759,6 @@
1676516759
'count' => 1,
1676616760
'path' => __DIR__ . '/tests/system/RESTful/ResourcePresenterTest.php',
1676716761
];
16768-
$ignoreErrors[] = [
16769-
// identifier: missingType.parameter
16770-
'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouterImprovedTest\\:\\:createNewAutoRouter\\(\\) has parameter \\$namespace with no type specified\\.$#',
16771-
'count' => 1,
16772-
'path' => __DIR__ . '/tests/system/Router/AutoRouterImprovedTest.php',
16773-
];
1677416762
$ignoreErrors[] = [
1677516763
// identifier: missingType.iterableValue
1677616764
'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouterImprovedTest\\:\\:provideRejectTranslateUriToCamelCase\\(\\) return type has no value type specified in iterable type iterable\\.$#',
@@ -17191,12 +17179,6 @@
1719117179
'count' => 1,
1719217180
'path' => __DIR__ . '/tests/system/Test/BootstrapFCPATHTest.php',
1719317181
];
17194-
$ignoreErrors[] = [
17195-
// identifier: missingType.parameter
17196-
'message' => '#^Method CodeIgniter\\\\Test\\\\BootstrapFCPATHTest\\:\\:readOutput\\(\\) has parameter \\$file with no type specified\\.$#',
17197-
'count' => 1,
17198-
'path' => __DIR__ . '/tests/system/Test/BootstrapFCPATHTest.php',
17199-
];
1720017182
$ignoreErrors[] = [
1720117183
// identifier: method.notFound
1720217184
'message' => '#^Call to an undefined method CodeIgniter\\\\Test\\\\TestResponse\\:\\:ohno\\(\\)\\.$#',

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
5151
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
5252
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
53+
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
5354
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
5455
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
5556
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
@@ -213,6 +214,7 @@
213214
ExplicitBoolCompareRector::class,
214215
AddClosureVoidReturnTypeWhereNoReturnRector::class,
215216
AddFunctionVoidReturnTypeWhereNoReturnRector::class,
217+
AddMethodCallBasedStrictParamTypeRector::class,
216218
])
217219
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
218220
// keep '\\' prefix string on string '\Foo\Bar'

system/Database/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3178,7 +3178,7 @@ protected function compileWhereHaving(string $qbKey): string
31783178
// 5 => ')' /* optional */
31793179
// );
31803180

3181-
if (! empty($matches[4])) {
3181+
if (isset($matches[4]) && $matches[4] !== '' && $matches[4] !== '0') {
31823182
$protectIdentifiers = false;
31833183
if (str_contains($matches[4], '.')) {
31843184
$protectIdentifiers = true;

system/Database/Postgre/Builder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,8 @@ static function ($key, $value) use ($table, $alias, $that) {
411411
* Returns cast expression.
412412
*
413413
* @TODO move this to BaseBuilder in 4.5.0
414-
*
415-
* @param float|int|string $expression
416414
*/
417-
private function cast($expression, ?string $type): string
415+
private function cast(string $expression, ?string $type): string
418416
{
419417
return ($type === null) ? $expression : 'CAST(' . $expression . ' AS ' . strtoupper($type) . ')';
420418
}

tests/system/API/ResponseTraitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ public function testValidContentTypes(): void
574574
}
575575
}
576576

577-
private function tryValidContentType($mimeType, $contentType): void
577+
private function tryValidContentType(string $mimeType, string $contentType): void
578578
{
579579
$original = $_SERVER;
580580
$_SERVER['CONTENT_TYPE'] = $mimeType;

tests/system/Router/AutoRouterImprovedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function setUp(): void
4545
$this->collection = new RouteCollection(Services::locator(), $moduleConfig, new Routing());
4646
}
4747

48-
private function createNewAutoRouter($namespace = 'CodeIgniter\Router\Controllers'): AutoRouterImproved
48+
private function createNewAutoRouter(string $namespace = 'CodeIgniter\Router\Controllers'): AutoRouterImproved
4949
{
5050
return new AutoRouterImproved(
5151
[],

tests/system/Test/BootstrapFCPATHTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private function fileContents()
102102
return $fileContents . ('echo FCPATH;' . PHP_EOL);
103103
}
104104

105-
private function readOutput($file)
105+
private function readOutput(string $file)
106106
{
107107
ob_start();
108108
system('php -f ' . $file);

0 commit comments

Comments
 (0)