Skip to content

Commit bc06c08

Browse files
committed
fix: TypeError in greater_than_equal_to
CodeIgniter\Validation\Rules::greater_than_equal_to(): Argument #1 ($str) must be of type ?string, int given
1 parent 41094eb commit bc06c08

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

system/Validation/StrictRules/Rules.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,14 @@ public function greater_than($str, string $min): bool
8181
/**
8282
* Equal to or Greater than
8383
*
84-
* @param mixed $str
84+
* @param mixed $str expects int|string
8585
*/
8686
public function greater_than_equal_to($str, string $min): bool
8787
{
88+
if (is_int($str)) {
89+
$str = (string) $str;
90+
}
91+
8892
return $this->nonStrictRules->greater_than_equal_to($str, $min);
8993
}
9094

tests/system/Validation/StrictRules/RulesTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,26 @@ public function providePermitEmptyCasesStrict(): Generator
8484
],
8585
];
8686
}
87+
88+
/**
89+
* @dataProvider provideGreaterThanEqualStrict
90+
*
91+
* @param int $value
92+
*/
93+
public function testGreaterThanEqualStrict($value, string $param, bool $expected): void
94+
{
95+
$this->validation->setRules(['foo' => "greater_than_equal_to[{$param}]"]);
96+
97+
$data = ['foo' => $value];
98+
$this->assertSame($expected, $this->validation->run($data));
99+
}
100+
101+
public function provideGreaterThanEqualStrict(): Generator
102+
{
103+
yield from [
104+
[0, '0', true],
105+
[1, '0', true],
106+
[-1, '0', false],
107+
];
108+
}
87109
}

0 commit comments

Comments
 (0)