Skip to content

Commit 68d2fed

Browse files
authored
Merge pull request #9156 from samsonasik/refactor-enable-add-method-call-based-param
refactor: enable AddMethodCallBasedStrictParamTypeRector
2 parents 2f78165 + 87eb71c commit 68d2fed

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\\.$#',
@@ -11445,7 +11451,7 @@
1144511451
];
1144611452
$ignoreErrors[] = [
1144711453
// identifier: codeigniter.superglobalAccessAssign
11448-
'message' => '#^Assigning mixed directly on offset \'CONTENT_TYPE\' of \\$_SERVER is discouraged\\.$#',
11454+
'message' => '#^Assigning string directly on offset \'CONTENT_TYPE\' of \\$_SERVER is discouraged\\.$#',
1144911455
'count' => 1,
1145011456
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
1145111457
];
@@ -11479,18 +11485,6 @@
1147911485
'count' => 1,
1148011486
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
1148111487
];
11482-
$ignoreErrors[] = [
11483-
// identifier: missingType.parameter
11484-
'message' => '#^Method CodeIgniter\\\\API\\\\ResponseTraitTest\\:\\:tryValidContentType\\(\\) has parameter \\$contentType with no type specified\\.$#',
11485-
'count' => 1,
11486-
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
11487-
];
11488-
$ignoreErrors[] = [
11489-
// identifier: missingType.parameter
11490-
'message' => '#^Method CodeIgniter\\\\API\\\\ResponseTraitTest\\:\\:tryValidContentType\\(\\) has parameter \\$mimeType with no type specified\\.$#',
11491-
'count' => 1,
11492-
'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php',
11493-
];
1149411488
$ignoreErrors[] = [
1149511489
// identifier: missingType.parameter
1149611490
'message' => '#^Method class@anonymous/tests/system/API/ResponseTraitTest\\.php\\:116\\:\\:__construct\\(\\) has parameter \\$formatter with no type specified\\.$#',
@@ -16759,12 +16753,6 @@
1675916753
'count' => 1,
1676016754
'path' => __DIR__ . '/tests/system/RESTful/ResourcePresenterTest.php',
1676116755
];
16762-
$ignoreErrors[] = [
16763-
// identifier: missingType.parameter
16764-
'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouterImprovedTest\\:\\:createNewAutoRouter\\(\\) has parameter \\$namespace with no type specified\\.$#',
16765-
'count' => 1,
16766-
'path' => __DIR__ . '/tests/system/Router/AutoRouterImprovedTest.php',
16767-
];
1676816756
$ignoreErrors[] = [
1676916757
// identifier: missingType.iterableValue
1677016758
'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouterImprovedTest\\:\\:provideRejectTranslateUriToCamelCase\\(\\) return type has no value type specified in iterable type iterable\\.$#',
@@ -17185,12 +17173,6 @@
1718517173
'count' => 1,
1718617174
'path' => __DIR__ . '/tests/system/Test/BootstrapFCPATHTest.php',
1718717175
];
17188-
$ignoreErrors[] = [
17189-
// identifier: missingType.parameter
17190-
'message' => '#^Method CodeIgniter\\\\Test\\\\BootstrapFCPATHTest\\:\\:readOutput\\(\\) has parameter \\$file with no type specified\\.$#',
17191-
'count' => 1,
17192-
'path' => __DIR__ . '/tests/system/Test/BootstrapFCPATHTest.php',
17193-
];
1719417176
$ignoreErrors[] = [
1719517177
// identifier: method.notFound
1719617178
'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)