diff --git a/phpstan-baseline.php b/phpstan-baseline.php index f0a882e68b01..4b1925646a8f 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1486,7 +1486,7 @@ $ignoreErrors[] = [ // identifier: empty.notAllowed 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 30, + 'count' => 29, 'path' => __DIR__ . '/system/Database/BaseBuilder.php', ]; $ignoreErrors[] = [ @@ -1933,6 +1933,12 @@ 'count' => 1, 'path' => __DIR__ . '/system/Database/BaseBuilder.php', ]; +$ignoreErrors[] = [ + // identifier: isset.offset + 'message' => '#^Offset 4 on array\\{string, string, string, string, string, string\\} in isset\\(\\) always exists and is not nullable\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Database/BaseBuilder.php', +]; $ignoreErrors[] = [ // identifier: booleanNot.exprNotBoolean 'message' => '#^Only booleans are allowed in a negated boolean, TWhenNot given\\.$#', @@ -11451,7 +11457,7 @@ ]; $ignoreErrors[] = [ // identifier: codeigniter.superglobalAccessAssign - 'message' => '#^Assigning mixed directly on offset \'CONTENT_TYPE\' of \\$_SERVER is discouraged\\.$#', + 'message' => '#^Assigning string directly on offset \'CONTENT_TYPE\' of \\$_SERVER is discouraged\\.$#', 'count' => 1, 'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php', ]; @@ -11485,18 +11491,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.parameter - 'message' => '#^Method CodeIgniter\\\\API\\\\ResponseTraitTest\\:\\:tryValidContentType\\(\\) has parameter \\$contentType with no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php', -]; -$ignoreErrors[] = [ - // identifier: missingType.parameter - 'message' => '#^Method CodeIgniter\\\\API\\\\ResponseTraitTest\\:\\:tryValidContentType\\(\\) has parameter \\$mimeType with no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/API/ResponseTraitTest.php', -]; $ignoreErrors[] = [ // identifier: missingType.parameter 'message' => '#^Method class@anonymous/tests/system/API/ResponseTraitTest\\.php\\:116\\:\\:__construct\\(\\) has parameter \\$formatter with no type specified\\.$#', @@ -16765,12 +16759,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/RESTful/ResourcePresenterTest.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.parameter - 'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouterImprovedTest\\:\\:createNewAutoRouter\\(\\) has parameter \\$namespace with no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/Router/AutoRouterImprovedTest.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Method CodeIgniter\\\\Router\\\\AutoRouterImprovedTest\\:\\:provideRejectTranslateUriToCamelCase\\(\\) return type has no value type specified in iterable type iterable\\.$#', @@ -17191,12 +17179,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/Test/BootstrapFCPATHTest.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.parameter - 'message' => '#^Method CodeIgniter\\\\Test\\\\BootstrapFCPATHTest\\:\\:readOutput\\(\\) has parameter \\$file with no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/Test/BootstrapFCPATHTest.php', -]; $ignoreErrors[] = [ // identifier: method.notFound 'message' => '#^Call to an undefined method CodeIgniter\\\\Test\\\\TestResponse\\:\\:ohno\\(\\)\\.$#', diff --git a/rector.php b/rector.php index d8ab56f3cc8e..e16de7bae441 100644 --- a/rector.php +++ b/rector.php @@ -50,6 +50,7 @@ use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector; +use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector; use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector; @@ -213,6 +214,7 @@ ExplicitBoolCompareRector::class, AddClosureVoidReturnTypeWhereNoReturnRector::class, AddFunctionVoidReturnTypeWhereNoReturnRector::class, + AddMethodCallBasedStrictParamTypeRector::class, ]) ->withConfiguredRule(StringClassNameToClassConstantRector::class, [ // keep '\\' prefix string on string '\Foo\Bar' diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 649a201112e4..d7fdc35287a1 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -3178,7 +3178,7 @@ protected function compileWhereHaving(string $qbKey): string // 5 => ')' /* optional */ // ); - if (! empty($matches[4])) { + if (isset($matches[4]) && $matches[4] !== '' && $matches[4] !== '0') { $protectIdentifiers = false; if (str_contains($matches[4], '.')) { $protectIdentifiers = true; diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index 1071dfedf06b..0d2dce0957ae 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -411,10 +411,8 @@ static function ($key, $value) use ($table, $alias, $that) { * Returns cast expression. * * @TODO move this to BaseBuilder in 4.5.0 - * - * @param float|int|string $expression */ - private function cast($expression, ?string $type): string + private function cast(string $expression, ?string $type): string { return ($type === null) ? $expression : 'CAST(' . $expression . ' AS ' . strtoupper($type) . ')'; } diff --git a/tests/system/API/ResponseTraitTest.php b/tests/system/API/ResponseTraitTest.php index 0887c673d616..82229b014bd4 100644 --- a/tests/system/API/ResponseTraitTest.php +++ b/tests/system/API/ResponseTraitTest.php @@ -574,7 +574,7 @@ public function testValidContentTypes(): void } } - private function tryValidContentType($mimeType, $contentType): void + private function tryValidContentType(string $mimeType, string $contentType): void { $original = $_SERVER; $_SERVER['CONTENT_TYPE'] = $mimeType; diff --git a/tests/system/Router/AutoRouterImprovedTest.php b/tests/system/Router/AutoRouterImprovedTest.php index 5975280bcdfd..0f4c75162a2f 100644 --- a/tests/system/Router/AutoRouterImprovedTest.php +++ b/tests/system/Router/AutoRouterImprovedTest.php @@ -45,7 +45,7 @@ protected function setUp(): void $this->collection = new RouteCollection(Services::locator(), $moduleConfig, new Routing()); } - private function createNewAutoRouter($namespace = 'CodeIgniter\Router\Controllers'): AutoRouterImproved + private function createNewAutoRouter(string $namespace = 'CodeIgniter\Router\Controllers'): AutoRouterImproved { return new AutoRouterImproved( [], diff --git a/tests/system/Test/BootstrapFCPATHTest.php b/tests/system/Test/BootstrapFCPATHTest.php index 61d2e1ca1695..d58bb847360d 100644 --- a/tests/system/Test/BootstrapFCPATHTest.php +++ b/tests/system/Test/BootstrapFCPATHTest.php @@ -102,7 +102,7 @@ private function fileContents() return $fileContents . ('echo FCPATH;' . PHP_EOL); } - private function readOutput($file) + private function readOutput(string $file) { ob_start(); system('php -f ' . $file);