IsInteger   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 2
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 11 4
1
<?php
2
/**
3
 * @author    Nurlan Mukhanov <[email protected]>
4
 * @copyright 2022 Nurlan Mukhanov
5
 * @license   https://en.wikipedia.org/wiki/MIT_License MIT License
6
 * @link      https://github.com/Falseclock/service-layer
7
 */
8
9
declare(strict_types=1);
10
11
namespace Falseclock\Service\Validation\Validators;
12
13
use Falseclock\Service\Validation\ValidationException;
14
use Falseclock\Service\Validation\ValidatorImpl;
15
16
class IsInteger extends ValidatorImpl
17
{
18
    public const ERROR_FLOAT_PROVIDED = "IsInteger class should not validate float values";
19
20
    /**
21
     * @param $value
22
     * @return bool
23
     * @throws ValidationException
24
     */
25
    public function check($value = null): bool
26
    {
27
        if (is_null($value) && $this->nullable) {
28
            return true;
29
        }
30
31
        if (is_float($value)) {
32
            throw new ValidationException(self::ERROR_FLOAT_PROVIDED);
33
        }
34
35
        return is_integer($value);
36
    }
37
}
38