Do not consider any float as integer

Values like "500.00" or 1.0 should not be considered as integer values
even though there is no data loss when they're converted to integer.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2018-06-23 21:05:43 +02:00
parent 0e73bc732e
commit 54d17abcee
No known key found for this signature in database
GPG key ID: 221E9281655813A6
2 changed files with 7 additions and 1 deletions

View file

@ -15,6 +15,10 @@ class IntVal extends AbstractRule
{
public function validate($input)
{
return is_numeric($input) && (int) $input == $input;
if (is_float($input)) {
return false;
}
return false !== filter_var($input, FILTER_VALIDATE_INT);
}
}

View file

@ -61,6 +61,8 @@ class IntValTest extends \PHPUnit_Framework_TestCase
[''],
[null],
['a'],
['1.0'],
[1.0],
[' '],
['Foo'],
['1.44'],