Passed
Push — master ( c9351b...a8a6df )
by Smoren
02:20
created

IntegerRule::odd()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Rules;
6
7
use Smoren\Validator\Checks\Check;
8
use Smoren\Validator\Interfaces\IntegerRuleInterface;
9
use Smoren\Validator\Structs\CheckErrorName;
10
use Smoren\Validator\Structs\CheckName;
11
12
class IntegerRule extends NumericRule implements IntegerRuleInterface
13
{
14
    /**
15
     * @param string $name
16
     */
17 57
    public function __construct(string $name)
18
    {
19 57
        Rule::__construct($name);
20 57
        $this->check(new Check(
21 57
            CheckName::INTEGER,
22 57
            CheckErrorName::NOT_INTEGER,
23 57
            fn ($value) => is_int($value),
24 57
            []
25 57
        ), true);
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     *
31
     * @return static
32
     */
33 11
    public function even(): self
34
    {
35 11
        return $this->check(new Check(
36 11
            CheckName::EVEN,
37 11
            CheckErrorName::NOT_EVEN,
38 11
            fn ($value) => $value % 2 === 0,
39 11
        ));
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     *
45
     * @return static
46
     */
47 12
    public function odd(): self
48
    {
49 12
        return $this->check(new Check(
50 12
            CheckName::ODD,
51 12
            CheckErrorName::NOT_ODD,
52 12
            fn ($value) => $value % 2 !== 0
53 12
        ));
54
    }
55
}
56