Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
7 / 7 |
Integer | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
7 / 7 |
validate | |
100.00% |
1 / 1 |
6 | |
100.00% |
6 / 6 |
|||
getInverseError | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
<?php | |
namespace Verja\Validator; | |
use Verja\Error; | |
use Verja\Validator; | |
class Integer extends Validator | |
{ | |
/** | |
* Validate $value | |
* | |
* @param mixed $value | |
* @param array $context | |
* @return bool | |
*/ | |
public function validate($value, array $context = []): bool | |
{ | |
if (is_int($value) || | |
(is_string($value) && is_numeric($value) || is_double($value)) && | |
(double)$value === round((double)$value) | |
) { | |
return true; | |
} | |
$this->error = new Error('NO_INTEGER', $value, 'value should be an integer'); | |
return false; | |
} | |
public function getInverseError($value) | |
{ | |
return new Error('IS_INTEGER', $value, 'value should not be an integer'); | |
} | |
} |