Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Integer
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
7
100.00% covered (success)
100.00%
1 / 1
 validate
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
6
 getInverseError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Verja\Validator;
4
5use Verja\Error;
6use Verja\Validator;
7
8class Integer extends Validator
9{
10    /**
11     * Validate $value
12     *
13     * @param mixed $value
14     * @param array $context
15     * @return bool
16     */
17    public function validate($value, array $context = []): bool
18    {
19        if (is_int($value) ||
20            (is_string($value) && is_numeric($value) || is_double($value)) &&
21            (double)$value === round((double)$value)
22        ) {
23            return true;
24        }
25
26        $this->error = new Error('NO_INTEGER', $value, 'value should be an integer');
27        return false;
28    }
29
30    public function getInverseError($value)
31    {
32        return new Error('IS_INTEGER', $value, 'value should not be an integer');
33    }
34}