Passed
Push — master ( cdfa93...96b6af )
by Smoren
02:36
created

IntegerRule::greaterOrEqual()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Smoren\Validator\Rules;
4
5
use Smoren\Validator\Interfaces\IntegerRuleInterface;
6
use Smoren\Validator\Interfaces\NumberRuleInterface;
7
use Smoren\Validator\Structs\Check;
8
9
class IntegerRule extends NumberRule implements IntegerRuleInterface
10
{
11
    public const ERROR_NOT_INTEGER = 'not_integer';
12
    public const ERROR_NOT_EVEN = 'not_even';
13
    public const ERROR_NOT_ODD = 'not_odd';
14
15 40
    public function __construct()
16
    {
17 40
        $this->add(new Check(
18 40
            self::ERROR_NOT_INTEGER,
19 40
            fn ($value) => is_int($value),
20 40
            [],
21 40
            true
22 40
        ));
23
    }
24
25
    /**
26
     * {@inheritDoc}
27
     *
28
     * @return static
29
     */
30 7
    public function even(): self
31
    {
32 7
        return $this->add(new Check(
33 7
            self::ERROR_NOT_EVEN,
34 7
            fn ($value) => $value % 2 === 0,
35 7
        ));
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     *
41
     * @return static
42
     */
43 10
    public function odd(): self
44
    {
45 10
        return $this->add(new Check(
46 10
            self::ERROR_NOT_ODD,
47 10
            fn ($value) => $value % 2 !== 0
48 10
        ));
49
    }
50
}
51