Skip to content

Commit

Permalink
Merge pull request #57 from coderi-sk/master
Browse files Browse the repository at this point in the history
Add float support for between rule
  • Loading branch information
emsifa authored Oct 29, 2018
2 parents 81ca951 + 7ada2ef commit 4c9261b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Rules/Between.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public function check($value)

$min = (int) $this->parameter('min');
$max = (int) $this->parameter('max');
if (is_int($value)) {

if (is_int($value) || is_float($value)) {
return $value >= $min AND $value <= $max;
} elseif(is_string($value)) {
return mb_strlen($value, 'UTF-8') >= $min AND mb_strlen($value, 'UTF-8') <= $max;
Expand Down
2 changes: 2 additions & 0 deletions tests/Rules/BetweenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function testValids()
$this->assertTrue($this->rule->fillParameters([6, 10])->check('футбол'));
$this->assertTrue($this->rule->fillParameters([2, 3])->check([1,2,3]));
$this->assertTrue($this->rule->fillParameters([100, 150])->check(123));
$this->assertTrue($this->rule->fillParameters([100, 150])->check(123.4));
}

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

}

0 comments on commit 4c9261b

Please sign in to comment.