LeapYearValidator::isValidLeapYear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Andegna\Validator;
4
5
/**
6
 * Ethiopian Leap Year Validator.
7
 */
8
class LeapYearValidator implements ValidatorInterface
9
{
10
    use ValidIntegerValidator;
11
12
    /** @var int */
13
    protected $year;
14
15
    /**
16
     * Leap Year Validator constructor.
17
     *
18
     * @param $year int the year
19
     */
20 77
    public function __construct($year)
21
    {
22 77
        $this->year = $year;
23 77
    }
24
25
    /**
26
     * @return bool true if valid
27
     */
28 77
    public function isValid()
29
    {
30
        return
31 77
            $this->isValidInteger($this->year) &&
32 77
            $this->isValidLeapYear($this->year);
33
    }
34
35
    /**
36
     * @param $year int
37
     *
38
     * @return bool true if valid
39
     */
40 77
    protected function isValidLeapYear($year)
41
    {
42 77
        return ($year + 1) % 4 === 0;
43
    }
44
}
45