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 bfc661c2b3d4..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 => [ @@ -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)) { 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(