IsIntegerNotEquals   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A against() 0 5 1
A check() 0 14 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
15
class IsIntegerNotEquals extends IsInteger
16
{
17
    public const ERROR_NOTHING_TO_COMPARE = "Nothing to compare";
18
    /** @var int */
19
    protected $against;
20
21
    /**
22
     * @param int $value
23
     * @return $this
24
     */
25
    public function against(int $value): IsIntegerNotEquals
26
    {
27
        $this->against = $value;
28
29
        return $this;
30
    }
31
32
    /**
33
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
34
     * @return bool
35
     * @throws ValidationException
36
     */
37
    public function check($value = null): bool
38
    {
39
        if (!parent::check($value)) {
40
            return true;
41
        }
42
43
        if (!isset($this->against)) {
44
            throw new ValidationException(self::ERROR_NOTHING_TO_COMPARE);
45
        }
46
47
        if ($value === $this->against)
48
            return false;
49
50
        return true;
51
    }
52
}
53