From 982f995331b4743ae7c8c319749dde160e8b6f53 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 28 Aug 2024 08:34:31 +0900 Subject: [PATCH 1/3] chore: fix link This workflow comments to PRs with conflicts. So it is better to link to "Updating Your Branch". --- .github/workflows/label-add-conflict-all-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-add-conflict-all-pr.yml b/.github/workflows/label-add-conflict-all-pr.yml index 5147d678f86c..e83e4daf0b99 100644 --- a/.github/workflows/label-add-conflict-all-pr.yml +++ b/.github/workflows/label-add-conflict-all-pr.yml @@ -46,6 +46,6 @@ jobs: gh pr edit $url --add-label "stale" # Add a comment - gh pr comment $url --body ":wave: Hi, @$author!

We detected conflicts in your PR against the base branch :speak_no_evil:
You may want to sync :arrows_counterclockwise: your branch with upstream!

Ref: [Syncing Your Branch](https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/workflow.md#pushing-your-branch)" + gh pr comment $url --body ":wave: Hi, @$author!

We detected conflicts in your PR against the base branch :speak_no_evil:
You may want to sync :arrows_counterclockwise: your branch with upstream!

Ref: [Syncing Your Branch](https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/workflow.md#updating-your-branch)" fi done From 87eb71ce293bfa634867a17d54a7d615610f978e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 28 Aug 2024 08:41:14 +0700 Subject: [PATCH 2/3] refactor: enable AddMethodCallBasedStrictParamTypeRector --- phpstan-baseline.php | 34 +++++-------------- rector.php | 2 ++ system/Database/BaseBuilder.php | 2 +- system/Database/Postgre/Builder.php | 4 +-- tests/system/API/ResponseTraitTest.php | 2 +- .../system/Router/AutoRouterImprovedTest.php | 2 +- tests/system/Test/BootstrapFCPATHTest.php | 2 +- 7 files changed, 15 insertions(+), 33 deletions(-) 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); From d12af0a4b4c3432486ef64a81ec133f6070aac44 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 29 Aug 2024 09:34:24 +0900 Subject: [PATCH 3/3] chore: update php-cs-fixer to ^3.63.2 --- utils/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/composer.json b/utils/composer.json index a982e299a79d..a204d68c0214 100644 --- a/utils/composer.json +++ b/utils/composer.json @@ -3,7 +3,7 @@ "php": "^8.1", "codeigniter/coding-standard": "^1.7", "ergebnis/composer-normalize": "^2.28", - "friendsofphp/php-cs-fixer": "3.62.*", + "friendsofphp/php-cs-fixer": "^3.63.2", "nexusphp/cs-config": "^3.6", "phpmetrics/phpmetrics": "^2.8 || ^3.0rc6", "vimeo/psalm": "^5.0"