From 6057b7d8ce306805e935dc30fe7bbba0ba902eb8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 24 Sep 2026 22:57:27 +0700 Subject: [PATCH 1/3] chore: fix phpstan notice on latest 2.2.15 --- composer.json | 2 +- tests/system/Config/ServicesTest.php | 3 ++- tests/system/Email/EmailTest.php | 3 ++- tests/system/Encryption/Handlers/OpenSSLHandlerTest.php | 3 ++- tests/system/Encryption/Handlers/SodiumHandlerTest.php | 3 ++- tests/system/Entity/EntityTest.php | 5 +++-- tests/system/Events/EventsTest.php | 3 ++- tests/system/HTTP/IncomingRequestTest.php | 3 ++- tests/system/HTTP/RequestTest.php | 3 ++- tests/system/Helpers/FormHelperTest.php | 9 ++++++--- tests/system/Helpers/TextHelperTest.php | 1 - tests/system/Language/LanguageTest.php | 6 ++++-- .../Session/Handlers/Database/RedisHandlerTest.php | 3 ++- tests/system/Throttle/ThrottleTest.php | 3 ++- tests/system/View/ParserTest.php | 3 ++- 15 files changed, 34 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index e703580fd4b9..b291ea49c21c 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "mikey179/vfsstream": "^1.6.12", "nexusphp/tachycardia": "^2.0", "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^2.2.1", + "phpstan/phpstan": "^2.2.15", "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpcov": "^9.0.2 || ^10.0", "phpunit/phpunit": "^10.5.16 || ^11.2", diff --git a/tests/system/Config/ServicesTest.php b/tests/system/Config/ServicesTest.php index 66c9158e67ab..f9b8d8158c39 100644 --- a/tests/system/Config/ServicesTest.php +++ b/tests/system/Config/ServicesTest.php @@ -197,7 +197,8 @@ public function testNewUnsharedLanguage(): void { $actual = Services::language(null, false); $this->assertInstanceOf(Language::class, $actual); - $this->assertSame('en', $actual->getLocale()); + $locale = $actual->getLocale(); + $this->assertSame('en', $locale); Services::language('la', false); $this->assertSame('en', $actual->getLocale()); diff --git a/tests/system/Email/EmailTest.php b/tests/system/Email/EmailTest.php index fc94686589d1..a54bf8d90ce5 100644 --- a/tests/system/Email/EmailTest.php +++ b/tests/system/Email/EmailTest.php @@ -713,7 +713,8 @@ public function testSetPriorityFallback(): void // Priority 6 is invalid, falls back to 3 $email->setPriority(6); - $this->assertSame(3, $this->getPrivateProperty($email, 'priority')); + $priority = $this->getPrivateProperty($email, 'priority'); + $this->assertSame(3, $priority); // Priority 0 is invalid, falls back to 3 $email->setPriority(0); diff --git a/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php b/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php index bac22a881f0a..01254f31b810 100644 --- a/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php +++ b/tests/system/Encryption/Handlers/OpenSSLHandlerTest.php @@ -149,7 +149,8 @@ public function testInternalKeyNotModifiedByParams(): void $encrypter = $this->encryption->initialize($params); $this->assertInstanceOf(OpenSSLHandler::class, $encrypter); - $this->assertSame('original-key-value', $encrypter->key); + $key = $encrypter->key; + $this->assertSame('original-key-value', $key); $message = 'This is a plain-text message.'; $differentKey = 'temporary-param-key'; diff --git a/tests/system/Encryption/Handlers/SodiumHandlerTest.php b/tests/system/Encryption/Handlers/SodiumHandlerTest.php index 47406cef00d0..fe63cec36fb9 100644 --- a/tests/system/Encryption/Handlers/SodiumHandlerTest.php +++ b/tests/system/Encryption/Handlers/SodiumHandlerTest.php @@ -139,7 +139,8 @@ public function testInternalKeyNotModifiedByParams(): void $encrypter = $this->encryption->initialize($this->config); $this->assertInstanceOf(SodiumHandler::class, $encrypter); - $this->assertSame($originalKey, $encrypter->key); + $key = $encrypter->key; + $this->assertSame($originalKey, $key); $message = 'This is a plain-text message.'; $differentKey = sodium_crypto_secretbox_keygen(); diff --git a/tests/system/Entity/EntityTest.php b/tests/system/Entity/EntityTest.php index be8f64f31775..3aff3fac3a10 100644 --- a/tests/system/Entity/EntityTest.php +++ b/tests/system/Entity/EntityTest.php @@ -373,8 +373,9 @@ public function testCastInteger(): void $entity->first = 3.1; - $this->assertIsInt($entity->first); - $this->assertSame(3, $entity->first); + $first = $entity->first; + $this->assertIsInt($first); + $this->assertSame(3, $first); $entity->first = 3.6; diff --git a/tests/system/Events/EventsTest.php b/tests/system/Events/EventsTest.php index bfdef1e2bbe9..39be06b1235b 100644 --- a/tests/system/Events/EventsTest.php +++ b/tests/system/Events/EventsTest.php @@ -69,7 +69,8 @@ public function testInitialize(): void // but we should be able to change it through the backdoor MockEvents::setFiles(['/peanuts']); - $this->assertSame(['/peanuts'], Events::getFiles()); + $files = Events::getFiles(); + $this->assertSame(['/peanuts'], $files); // re-initializing should have no effect MockEvents::initialize(); diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index 90e6c7d57e90..464b46e2ce2c 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -1057,7 +1057,8 @@ public function testGetIPAddressNormal(): void $request = new Request(new App()); $request->populateHeaders(); - $this->assertSame($expected, $request->getIPAddress()); + $ipAddress = $request->getIPAddress(); + $this->assertSame($expected, $ipAddress); // call a second time to exercise the initial conditional block in getIPAddress() $this->assertSame($expected, $request->getIPAddress()); } diff --git a/tests/system/HTTP/RequestTest.php b/tests/system/HTTP/RequestTest.php index e1f70bdd272f..2dafdc4fd792 100644 --- a/tests/system/HTTP/RequestTest.php +++ b/tests/system/HTTP/RequestTest.php @@ -562,7 +562,8 @@ public function testGetIPAddressNormal(): void $expected = '123.123.123.123'; service('superglobals')->setServer('REMOTE_ADDR', $expected); $this->request = new Request(new App()); - $this->assertSame($expected, $this->request->getIPAddress()); + $ipAddress = $this->request->getIPAddress(); + $this->assertSame($expected, $ipAddress); // call a second time to exercise the initial conditional block in getIPAddress() $this->assertSame($expected, $this->request->getIPAddress()); } diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index 73cbe2430a5f..c24d34b04a3e 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -870,7 +870,8 @@ public function testSetValue(): void public function testSetSelect(): void { $_SESSION['_ci_old_input']['post']['foo'] = 'bar'; - $this->assertSame(' selected="selected"', set_select('foo', 'bar')); + $selected = set_select('foo', 'bar'); + $this->assertSame(' selected="selected"', $selected); $_SESSION['_ci_old_input']['post']['foo'] = ['foo' => 'bar']; $this->assertSame(' selected="selected"', set_select('foo', 'bar')); @@ -890,7 +891,8 @@ public function testSetCheckbox(): void ], ]; - $this->assertSame(' checked="checked"', set_checkbox('foo', 'bar')); + $checked = set_checkbox('foo', 'bar'); + $this->assertSame(' checked="checked"', $checked); $_SESSION = [ '_ci_old_input' => [ @@ -919,7 +921,8 @@ public function testSetCheckboxWithValueZero(): void ], ]; - $this->assertSame(' checked="checked"', set_checkbox('foo', '0')); + $checked = set_checkbox('foo', '0'); + $this->assertSame(' checked="checked"', $checked); $_SESSION = [ '_ci_old_input' => [ diff --git a/tests/system/Helpers/TextHelperTest.php b/tests/system/Helpers/TextHelperTest.php index 212f2797bacf..c409812b2cdb 100644 --- a/tests/system/Helpers/TextHelperTest.php +++ b/tests/system/Helpers/TextHelperTest.php @@ -162,7 +162,6 @@ public function testIncrementString(): void $this->assertSame('my-test-1', increment_string('my-test', '-')); $this->assertSame('file_5', increment_string('file_4')); $this->assertSame('file-5', increment_string('file-4', '-')); - $this->assertSame('file-5', increment_string('file-4', '-')); $this->assertSame('file-1', increment_string('file', '-', 1)); $this->assertSame('124', increment_string('123', '')); } diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index 6233941e7d75..b67292da2236 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -338,10 +338,12 @@ public function testLangKeepLocale(): void $lang = service('language', 'en', true); lang('Language.languageGetLineInvalidArgumentException'); - $this->assertSame('en', $lang->getLocale()); + $locale = $lang->getLocale(); + $this->assertSame('en', $locale); lang('Language.languageGetLineInvalidArgumentException', [], 'ru'); - $this->assertSame('en', $lang->getLocale()); + $locale = $lang->getLocale(); + $this->assertSame('en', $locale); lang('Language.languageGetLineInvalidArgumentException'); $this->assertSame('en', $lang->getLocale()); diff --git a/tests/system/Session/Handlers/Database/RedisHandlerTest.php b/tests/system/Session/Handlers/Database/RedisHandlerTest.php index 637132669aec..c2f549e31659 100644 --- a/tests/system/Session/Handlers/Database/RedisHandlerTest.php +++ b/tests/system/Session/Handlers/Database/RedisHandlerTest.php @@ -142,7 +142,8 @@ public function testSecondaryReadAfterClose(): void $expected = <<<'DATA' __ci_last_regenerate|i:1664607454;_ci_previous_url|s:32:"http://localhost:8080/index.php/";key|s:5:"value"; DATA; - $this->assertSame($expected, $handler->read('555556b43phsnnf8if6bo33b635e4447')); + $data = $handler->read('555556b43phsnnf8if6bo33b635e4447'); + $this->assertSame($expected, $data); $handler->close(); diff --git a/tests/system/Throttle/ThrottleTest.php b/tests/system/Throttle/ThrottleTest.php index 98751a86781b..b16606341ab7 100644 --- a/tests/system/Throttle/ThrottleTest.php +++ b/tests/system/Throttle/ThrottleTest.php @@ -39,7 +39,8 @@ public function testTokenTime(): void $throttler = new Throttler($this->cache); // tokenTime should be 0 to start - $this->assertSame(0, $throttler->getTokenTime()); + $tokenTime = $throttler->getTokenTime(); + $this->assertSame(0, $tokenTime); // set $rate $rate = 1; // allow 1 request per minute diff --git a/tests/system/View/ParserTest.php b/tests/system/View/ParserTest.php index 95d807729c58..36e8707430d6 100644 --- a/tests/system/View/ParserTest.php +++ b/tests/system/View/ParserTest.php @@ -962,7 +962,8 @@ public function testCachedRender(): void $this->parser->setVar('teststring', 'Hello World'); $expected = "

Hello World

\n"; - $this->assertSame($expected, $this->parser->render('template1', ['cache' => 10, 'cache_name' => 'HelloWorld'])); + $output = $this->parser->render('template1', ['cache' => 10, 'cache_name' => 'HelloWorld']); + $this->assertSame($expected, $output); // this second renderings should go thru the cache $this->assertSame($expected, $this->parser->render('template1', ['cache' => 10, 'cache_name' => 'HelloWorld'])); } From b5ade993c5f5340e4481cf94a083af603e35cec5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 24 Sep 2026 23:00:30 +0700 Subject: [PATCH 2/3] chore: regenerate baseline for on purpose test --- tests/system/Helpers/TextHelperTest.php | 1 + utils/phpstan-baseline/loader.neon | 3 ++- utils/phpstan-baseline/method.alreadyNarrowedType.neon | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 utils/phpstan-baseline/method.alreadyNarrowedType.neon diff --git a/tests/system/Helpers/TextHelperTest.php b/tests/system/Helpers/TextHelperTest.php index c409812b2cdb..212f2797bacf 100644 --- a/tests/system/Helpers/TextHelperTest.php +++ b/tests/system/Helpers/TextHelperTest.php @@ -162,6 +162,7 @@ public function testIncrementString(): void $this->assertSame('my-test-1', increment_string('my-test', '-')); $this->assertSame('file_5', increment_string('file_4')); $this->assertSame('file-5', increment_string('file-4', '-')); + $this->assertSame('file-5', increment_string('file-4', '-')); $this->assertSame('file-1', increment_string('file', '-', 1)); $this->assertSame('124', increment_string('123', '')); } diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index c00a0da66add..8505cb6e06d8 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,10 +1,11 @@ -# total 12 errors +# total 13 errors includes: - arguments.count.neon - assign.propertyType.neon - deadCode.unreachable.neon - function.resultUnused.neon + - method.alreadyNarrowedType.neon - method.childReturnType.neon - property.defaultValue.neon - property.phpDocType.neon diff --git a/utils/phpstan-baseline/method.alreadyNarrowedType.neon b/utils/phpstan-baseline/method.alreadyNarrowedType.neon new file mode 100644 index 000000000000..a4d36b4919ef --- /dev/null +++ b/utils/phpstan-baseline/method.alreadyNarrowedType.neon @@ -0,0 +1,8 @@ +# total 1 error + +parameters: + ignoreErrors: + - + message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertSame\(\) with ''file\-5'' and ''file\-5'' will always evaluate to true\.$#' + count: 1 + path: ../../tests/system/Helpers/TextHelperTest.php From 18e39860ce8b2811b57e3029250ac89e1568b737 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 24 Sep 2026 23:31:17 +0700 Subject: [PATCH 3/3] final touch: avoid regenerate baseline, fix instead --- tests/system/Helpers/TextHelperTest.php | 3 ++- utils/phpstan-baseline/loader.neon | 3 +-- utils/phpstan-baseline/method.alreadyNarrowedType.neon | 8 -------- 3 files changed, 3 insertions(+), 11 deletions(-) delete mode 100644 utils/phpstan-baseline/method.alreadyNarrowedType.neon diff --git a/tests/system/Helpers/TextHelperTest.php b/tests/system/Helpers/TextHelperTest.php index 212f2797bacf..a4702db4b604 100644 --- a/tests/system/Helpers/TextHelperTest.php +++ b/tests/system/Helpers/TextHelperTest.php @@ -161,7 +161,8 @@ public function testIncrementString(): void $this->assertSame('my-test_1', increment_string('my-test')); $this->assertSame('my-test-1', increment_string('my-test', '-')); $this->assertSame('file_5', increment_string('file_4')); - $this->assertSame('file-5', increment_string('file-4', '-')); + $incremented = increment_string('file-4', '-'); + $this->assertSame('file-5', $incremented); $this->assertSame('file-5', increment_string('file-4', '-')); $this->assertSame('file-1', increment_string('file', '-', 1)); $this->assertSame('124', increment_string('123', '')); diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 8505cb6e06d8..c00a0da66add 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,11 +1,10 @@ -# total 13 errors +# total 12 errors includes: - arguments.count.neon - assign.propertyType.neon - deadCode.unreachable.neon - function.resultUnused.neon - - method.alreadyNarrowedType.neon - method.childReturnType.neon - property.defaultValue.neon - property.phpDocType.neon diff --git a/utils/phpstan-baseline/method.alreadyNarrowedType.neon b/utils/phpstan-baseline/method.alreadyNarrowedType.neon deleted file mode 100644 index a4d36b4919ef..000000000000 --- a/utils/phpstan-baseline/method.alreadyNarrowedType.neon +++ /dev/null @@ -1,8 +0,0 @@ -# total 1 error - -parameters: - ignoreErrors: - - - message: '#^Call to method PHPUnit\\Framework\\Assert\:\:assertSame\(\) with ''file\-5'' and ''file\-5'' will always evaluate to true\.$#' - count: 1 - path: ../../tests/system/Helpers/TextHelperTest.php