Skip to content

Commit 7ada2ef

Browse files
committed
Add float support for between rule
1 parent 81ca951 commit 7ada2ef

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Rules/Between.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public function check($value)
1717

1818
$min = (int) $this->parameter('min');
1919
$max = (int) $this->parameter('max');
20-
21-
if (is_int($value)) {
20+
21+
if (is_int($value) || is_float($value)) {
2222
return $value >= $min AND $value <= $max;
2323
} elseif(is_string($value)) {
2424
return mb_strlen($value, 'UTF-8') >= $min AND mb_strlen($value, 'UTF-8') <= $max;

tests/Rules/BetweenTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function testValids()
1616
$this->assertTrue($this->rule->fillParameters([6, 10])->check('футбол'));
1717
$this->assertTrue($this->rule->fillParameters([2, 3])->check([1,2,3]));
1818
$this->assertTrue($this->rule->fillParameters([100, 150])->check(123));
19+
$this->assertTrue($this->rule->fillParameters([100, 150])->check(123.4));
1920
}
2021

2122
public function testInvalids()
@@ -24,6 +25,7 @@ public function testInvalids()
2425
$this->assertFalse($this->rule->fillParameters([2, 5])->check('футбол'));
2526
$this->assertFalse($this->rule->fillParameters([4, 6])->check([1,2,3]));
2627
$this->assertFalse($this->rule->fillParameters([50, 100])->check(123));
28+
$this->assertFalse($this->rule->fillParameters([50, 100])->check(123.4));
2729
}
2830

2931
}

0 commit comments

Comments
 (0)