Skip to content

Commit

Permalink
fix: isList when passing a string
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault JUNIN <[email protected]>
  • Loading branch information
thibaultjunin committed Oct 24, 2023
1 parent 6fd92cf commit 852067c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public function getErrors(): array
public function list(string ...$keys)
{
foreach ($keys as $key) {
if (!empty($this->getValue($key)) && !array_is_list($this->getValue($key))) {
if (!empty($this->getValue($key)) && (!is_array($this->getValue($key)) || !array_is_list($this->getValue($key)))) {
$this->addError($key, ValidationRules::LIST);
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public function testList()
$validator = $this->createValidator(["abc" => ["abc" => "def", "foo" => "bar"]]);
$validator->list("abc");
$this->assertCount(1, $validator->getErrors(), json_encode($validator->getErrors()));

$validator = $this->createValidator(["abc" => "str"]);
$validator->list("abc");
$this->assertCount(1, $validator->getErrors(), json_encode($validator->getErrors()));
}

}

0 comments on commit 852067c

Please sign in to comment.