diff --git a/admin/docs-phpstan-baseline.php b/admin/docs-phpstan-baseline.php index 0c3fe032e485..5885a3dcfda9 100644 --- a/admin/docs-phpstan-baseline.php +++ b/admin/docs-phpstan-baseline.php @@ -91,6 +91,13 @@ ], ], + [ + 'identifier' => 'codeigniter.languageLineNotFound', + 'paths' => [ + 'docs/outgoing/localization.md:359', + ], + ], + [ 'identifier' => 'deadCode.unreachable', 'paths' => [ diff --git a/composer.json b/composer.json index ad36b57e1304..803ae6eb46b3 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require-dev": { "boundwize/structarmed": "^0.21", - "codeigniter/phpstan-codeigniter": "^2.1", + "codeigniter/phpstan-codeigniter": "^2.3", "fakerphp/faker": "^1.24", "kint-php/kint": "^6.1", "mikey179/vfsstream": "^1.6.12", diff --git a/system/HTTP/Exceptions/HTTPException.php b/system/HTTP/Exceptions/HTTPException.php index 9a72ca6909f9..25b0cb431410 100644 --- a/system/HTTP/Exceptions/HTTPException.php +++ b/system/HTTP/Exceptions/HTTPException.php @@ -236,7 +236,7 @@ public static function forMoveFailed(string $source, string $target, string $err */ public static function forInvalidSameSiteSetting(string $samesite) { - return new static(lang('Security.invalidSameSiteSetting', [$samesite])); + return new static(lang('HTTP.invalidSameSiteSetting', [$samesite])); } /** diff --git a/system/Honeypot/Exceptions/HoneypotException.php b/system/Honeypot/Exceptions/HoneypotException.php index c8eedeb311f6..57c1c871ff4e 100644 --- a/system/Honeypot/Exceptions/HoneypotException.php +++ b/system/Honeypot/Exceptions/HoneypotException.php @@ -47,7 +47,7 @@ public static function forNoNameField() */ public static function forNoHiddenValue() { - return new static(lang('Honeypot.noHiddenValue'), 500); + return new static(lang('Honeypot.noHiddenValue'), 500); // @phpstan-ignore codeigniter.languageLineNotFound } /** diff --git a/tests/system/Config/FactoriesTest.php b/tests/system/Config/FactoriesTest.php index abaef3997a88..b175ee6f12f6 100644 --- a/tests/system/Config/FactoriesTest.php +++ b/tests/system/Config/FactoriesTest.php @@ -220,7 +220,7 @@ public function testRespectsPath(): void { Factories::setOptions('models', ['path' => 'Widgets']); - $result = Factories::models('SomeWidget'); + $result = Factories::models('SomeWidget'); // @phpstan-ignore codeigniter.modelArgumentType $this->assertInstanceOf(SomeWidget::class, $result); } @@ -275,7 +275,7 @@ class TestRegistrar EOL; file_put_contents($file, $source); - $result = Factories::config('TestRegistrar'); + $result = Factories::config('TestRegistrar'); // @phpstan-ignore codeigniter.configArgumentType // @phpstan-ignore argument.type (Config\TestRegistrar is created at runtime by this test) $this->assertInstanceOf('Config\TestRegistrar', $result); @@ -296,13 +296,13 @@ class TestRegistrar EOL; file_put_contents($file, $source); - $result = Factories::config(TestRegistrar::class); + $result = Factories::config(TestRegistrar::class); // @phpstan-ignore codeigniter.configArgumentInstanceof $this->assertInstanceOf(TestRegistrar::class, $result); Factories::setOptions('config', ['preferApp' => false]); - $result = Factories::config(TestRegistrar::class); + $result = Factories::config(TestRegistrar::class); // @phpstan-ignore codeigniter.configArgumentInstanceof $this->assertInstanceOf(TestRegistrar::class, $result); @@ -522,7 +522,7 @@ public function testGetCreatesConfigInstanceAndFactoriesConfigReturnsIt(): void public function testGetNonexistentClass(): void { - $config = Factories::get('config', 'NonexistentClass'); + $config = Factories::get('config', 'NonexistentClass'); // @phpstan-ignore codeigniter.configArgumentType $this->assertNull($config); } diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index b67292da2236..44dcfeb3d461 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -324,10 +324,10 @@ public function testBaseLocaleVsVariants(): void $this->assertSame('I have a very bad feeling about this', $lang->getLine('More.cannotMove')); // key is in variant but not base; should pick variant - $this->assertSame('There is no try', $lang->getLine('More.wisdom')); + $this->assertSame('There is no try', $lang->getLine('More.wisdom')); // @phpstan-ignore codeigniter.languageLineNotFound // key isn't in either base or variant; should return bad key - $this->assertSame('More.shootMe', $lang->getLine('More.shootMe')); + $this->assertSame('More.shootMe', $lang->getLine('More.shootMe')); // @phpstan-ignore codeigniter.languageLineNotFound } /** @@ -365,10 +365,10 @@ public function testLangKeepLocale(): void public function testAllTheWayFallbacks(): void { $lang = service('language', 'ab-CD', false); - $this->assertSame('Allin.none', $lang->getLine('Allin.none')); - $this->assertSame('Pyramid of Giza', $lang->getLine('Allin.one')); - $this->assertSame('gluttony', $lang->getLine('Allin.two')); - $this->assertSame('Colossus of Rhodes', $lang->getLine('Allin.tre')); + $this->assertSame('Allin.none', $lang->getLine('Allin.none')); // @phpstan-ignore codeigniter.languageLineNotFound + $this->assertSame('Pyramid of Giza', $lang->getLine('Allin.one')); // @phpstan-ignore codeigniter.languageLineNotFound + $this->assertSame('gluttony', $lang->getLine('Allin.two')); // @phpstan-ignore codeigniter.languageLineNotFound + $this->assertSame('Colossus of Rhodes', $lang->getLine('Allin.tre')); // @phpstan-ignore codeigniter.languageLineNotFound $this->assertSame('four calling birds', $lang->getLine('Allin.for')); $this->assertSame('Temple of Artemis', $lang->getLine('Allin.fiv')); $this->assertSame('envy', $lang->getLine('Allin.six')); @@ -402,6 +402,6 @@ public function testLanguageKeySeparatedByDot(): void $lang->loadem('Foo', 'en'); $this->assertSame('The fieldname field is very short.', $lang->getLine('Foo.bar.min_length1', ['field' => 'fieldname'])); - $this->assertSame('The fieldname field is very short.', $lang->getLine('Foo.baz.min_length3.short', ['field' => 'fieldname'])); + $this->assertSame('The fieldname field is very short.', $lang->getLine('Foo.baz.min_length3.short', ['field' => 'fieldname'])); // @phpstan-ignore codeigniter.languageLineNotFound } } diff --git a/tests/system/Models/DataConverterModelTest.php b/tests/system/Models/DataConverterModelTest.php index f26f03d999b9..ee0940ba88bb 100644 --- a/tests/system/Models/DataConverterModelTest.php +++ b/tests/system/Models/DataConverterModelTest.php @@ -291,7 +291,7 @@ public function testUpdateArray(): void $user = $this->model->find($id); $user['email'][] = 'private@example.org'; - $this->model->update($user['id'], $user); + $this->model->update($user['id'], $user); // @phpstan-ignore codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed $user = $this->model->find($id); @@ -358,7 +358,7 @@ public function testSaveArray(): void $user = $this->model->find($id); $user['email'][] = 'private@example.org'; - $this->model->save($user); + $this->model->save($user); // @phpstan-ignore codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed $user = $this->model->find($id); diff --git a/tests/system/Models/EventsModelTest.php b/tests/system/Models/EventsModelTest.php index 82e49952c7a2..500e2252980a 100644 --- a/tests/system/Models/EventsModelTest.php +++ b/tests/system/Models/EventsModelTest.php @@ -45,7 +45,7 @@ public function testInsertEvent(): void 'deleted' => 0, ]; - $this->model()->insert($data); + $this->model()->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->assertTrue($this->model()->hasToken('beforeInsert')); $this->assertTrue($this->model()->hasToken('afterInsert')); } @@ -59,9 +59,9 @@ public function testUpdateEvent(): void 'deleted' => 0, ]; - $id = $this->model()->insert($data); + $id = $this->model()->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed - $this->model()->update($id, $data); + $this->model()->update($id, $data); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->assertTrue($this->model()->hasToken('beforeUpdate')); $this->assertTrue($this->model()->hasToken('afterUpdate')); } @@ -174,7 +174,7 @@ public function testInvalidEventException(): void $this->expectException(DataException::class); $this->expectExceptionMessage('"anotherBeforeInsertMethod" is not a valid Model Event callback.'); - $this->model()->insert($data); + $this->model()->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed } public function testInsertBatchEvent(): void diff --git a/tests/system/Models/InsertModelTest.php b/tests/system/Models/InsertModelTest.php index ccaa8e9cf4ac..b5d052f63ab2 100644 --- a/tests/system/Models/InsertModelTest.php +++ b/tests/system/Models/InsertModelTest.php @@ -179,7 +179,7 @@ public function testInsertResultFail(): void ]; $this->createModel(JobModel::class); - $result = $this->model->protect(false)->insert($data, false); + $result = $this->model->protect(false)->insert($data, false); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->assertFalse($result); @@ -278,7 +278,7 @@ public function testInsertArrayWithNoDataExceptionNoAllowedData(): void { $this->expectException(DataException::class); $this->expectExceptionMessage('There is no data to insert.'); - $this->createModel(UserModel::class)->insert(['thisKeyIsNotAllowed' => 'Bar']); + $this->createModel(UserModel::class)->insert(['thisKeyIsNotAllowed' => 'Bar']); // @phpstan-ignore codeigniter.modelFieldNotAllowed } public function testInsertEntityWithNoDataExceptionNoAllowedData(): void @@ -320,7 +320,7 @@ public function testUseAutoIncrementSetToFalseInsert(): void ]; $this->createModel(WithoutAutoIncrementModel::class); - $this->model->insert($insert); + $this->model->insert($insert); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->assertSame($insert['key'], $this->model->getInsertID()); $this->seeInDatabase('without_auto_increment', $insert); @@ -413,7 +413,7 @@ public function testInsertWithInvalidPrimaryKeyWhenAutoIncrementDisabled( 'value' => 'some value', ]; - $this->createModel(WithoutAutoIncrementModel::class)->insert($insert); + $this->createModel(WithoutAutoIncrementModel::class)->insert($insert); // @phpstan-ignore codeigniter.modelFieldNotAllowed } /** diff --git a/tests/system/Models/SaveModelTest.php b/tests/system/Models/SaveModelTest.php index 246bd8e6142c..2f3096cb9112 100644 --- a/tests/system/Models/SaveModelTest.php +++ b/tests/system/Models/SaveModelTest.php @@ -58,7 +58,7 @@ public function testSaveNewRecordArrayWithEmptyStringId(): void 'description' => 'Makes peoples things dissappear.', ]; - $this->model->save($data); + $this->model->save($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->seeInDatabase('job', ['name' => 'Magician']); } @@ -86,7 +86,7 @@ public function testSaveNewRecordArrayFail(): void 'name123' => 'Apprentice', 'description' => 'That thing you do.', ]; - $result = $this->model->protect(false)->save($data); + $result = $this->model->protect(false)->save($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->assertFalse($result); $this->dontSeeInDatabase('job', ['name' => 'Apprentice']); @@ -119,7 +119,7 @@ public function testSaveUpdateRecordArrayFail(): void 'name123' => 'Apprentice', 'description' => 'That thing you do.', ]; - $result = $this->model->protect(false)->save($data); + $result = $this->model->protect(false)->save($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed $this->assertFalse($result); $this->dontSeeInDatabase('job', ['name' => 'Apprentice']); @@ -210,7 +210,7 @@ public function testSetTable(): void 'description' => 'That thing you do.', ]; - $this->model->protect(false)->save($data); + $this->model->protect(false)->save($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed $lastInsertId = $this->model->getInsertID(); $this->seeInDatabase('job', ['id' => $lastInsertId]); } @@ -325,7 +325,7 @@ public function testUseAutoIncrementSetToFalseSave(): void ]; $this->createModel(WithoutAutoIncrementModel::class); - $this->model->save($insert); + $this->model->save($insert); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->assertSame($insert['key'], $this->model->getInsertID()); $this->seeInDatabase('without_auto_increment', $insert); diff --git a/tests/system/Models/TimestampModelTest.php b/tests/system/Models/TimestampModelTest.php index f87f54772831..4ea1638e5fc6 100644 --- a/tests/system/Models/TimestampModelTest.php +++ b/tests/system/Models/TimestampModelTest.php @@ -148,7 +148,7 @@ public function testDoNotAllowDatesUpdateArrayUpdatesUpdatedAt(): void $user = $this->model->find($id); $user['country'] = 'CA'; - $this->model->update($user['id'], $user); + $this->model->update($user['id'], $user); // @phpstan-ignore codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed $user = $this->model->find($id); @@ -265,7 +265,7 @@ public function testAllowDatesUpdateArrayUpdatesUpdatedAt(): void $user = $this->model->find($id); $user['country'] = 'CA'; - $this->model->update($user['id'], $user); + $this->model->update($user['id'], $user); // @phpstan-ignore codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed $user = $this->model->find($id); diff --git a/tests/system/Models/UpdateModelTest.php b/tests/system/Models/UpdateModelTest.php index 23279dc5b968..995f764b1e9c 100644 --- a/tests/system/Models/UpdateModelTest.php +++ b/tests/system/Models/UpdateModelTest.php @@ -100,7 +100,7 @@ public function testUpdateArray(): void ]; $this->createModel(UserModel::class); - $this->model->insert($data); + $this->model->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed $result = $this->model->update([1, 2], ['name' => 'Foo Bar']); $this->assertTrue($result); @@ -130,11 +130,11 @@ public function testUpdateResultFail(): void 'country' => 'US', 'deleted' => 0, ]; - $this->model->insert($data); + $this->model->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->setPrivateProperty($this->model, 'allowedFields', ['name123']); - $result = $this->model->update(1, ['name123' => 'Foo Bar 1']); + $result = $this->model->update(1, ['name123' => 'Foo Bar 1']); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->assertFalse($result); $this->dontSeeInDatabase('user', ['id' => 1, 'name' => 'Foo Bar 1']); @@ -327,7 +327,7 @@ public function testUpdateArrayWithDataException(): void 'deleted' => 0, ]; - $id = $this->model->insert($data); + $id = $this->model->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->expectException(DataException::class); $this->expectExceptionMessage('There is no data to update.'); @@ -365,7 +365,7 @@ public function testUpdateArrayWithDataExceptionNoAllowedFields(): void 'deleted' => 0, ]; - $id = $this->model->insert($data); + $id = $this->model->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed $this->expectException(DataException::class); $this->expectExceptionMessage('There is no data to update.'); diff --git a/tests/system/Models/ValidationModelRuleGroupTest.php b/tests/system/Models/ValidationModelRuleGroupTest.php index 8059e1fee7d2..09b8b0ff5c2a 100644 --- a/tests/system/Models/ValidationModelRuleGroupTest.php +++ b/tests/system/Models/ValidationModelRuleGroupTest.php @@ -317,7 +317,7 @@ public function testValidationIncludingErrors(): void $this->createModel(ValidErrorsModel::class); - $id = $this->model->insert($data); + $id = $this->model->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed $this->assertFalse((bool) $id); $this->assertSame('Minimum Length Error', $this->model->errors()['name']); } diff --git a/tests/system/Models/ValidationModelTest.php b/tests/system/Models/ValidationModelTest.php index ba03bea98231..02ddbd8a42c8 100644 --- a/tests/system/Models/ValidationModelTest.php +++ b/tests/system/Models/ValidationModelTest.php @@ -333,7 +333,7 @@ public function testValidationIncludingErrors(): void $this->createModel(ValidErrorsModel::class); - $id = $this->model->insert($data); + $id = $this->model->insert($data); // @phpstan-ignore codeigniter.modelFieldNotAllowed, codeigniter.modelFieldNotAllowed $this->assertFalse((bool) $id); $this->assertSame('Minimum Length Error', $this->model->errors()['name']); }