From dbff203d1e27a3b1ab66107d14b683775743d6e3 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Aug 2024 08:25:00 +0900 Subject: [PATCH 1/3] test: add test for numeric field name --- tests/system/Validation/ValidationTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index b5493a682c8e..00360f368e66 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -270,6 +270,16 @@ public function testRunDoesTheBasics(): void $this->assertSame([], $this->validation->getValidated()); } + public function testRunWithNumericFieldName(): void + { + // The array key will be int. + $data = ['123' => 'notanumber']; + $this->validation->setRules(['123' => 'is_numeric']); + + $this->assertFalse($this->validation->run($data)); + $this->assertSame([], $this->validation->getValidated()); + } + public function testClosureRule(): void { $this->validation->setRules( From 99f41ee353215dfc32d3126e10508b3fc0d08e57 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Aug 2024 08:26:35 +0900 Subject: [PATCH 2/3] fix: TypeError when there is numeric field name TypeError: str_contains(): Argument #1 ($haystack) must be of type string, int given --- system/Validation/Validation.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index bfc661c2b3d4..c183a5bb739b 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -163,6 +163,9 @@ public function run(?array $data = null, ?string $group = null, $dbGroup = null) // Run through each rule. If we have any field set for // this rule, then we need to run them through! foreach ($this->rules as $field => $setup) { + // An array key might be int. + $field = (string) $field; + $rules = $setup['rules']; if (is_string($rules)) { From 2979ece9a39977b2429b01e0ca724e46be2a994c Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 23 Aug 2024 08:30:22 +0900 Subject: [PATCH 3/3] docs: make @var more precise --- phpstan-baseline.php | 6 ------ system/Validation/Validation.php | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index f0a882e68b01..c48093046742 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -10459,12 +10459,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/Validation/Validation.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Property CodeIgniter\\\\Validation\\\\Validation\\:\\:\\$rules type has no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Validation/Validation.php', -]; $ignoreErrors[] = [ // identifier: missingType.iterableValue 'message' => '#^Property CodeIgniter\\\\Validation\\\\Validation\\:\\:\\$validated type has no value type specified in iterable type array\\.$#', diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php index c183a5bb739b..a4d817d2a9b4 100644 --- a/system/Validation/Validation.php +++ b/system/Validation/Validation.php @@ -51,7 +51,7 @@ class Validation implements ValidationInterface /** * Stores the actual rules that should be run against $data. * - * @var array + * @var array}> * * [ * field1 => [