Persian::isLeapYear()   B
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 12
nop 1
dl 0
loc 22
rs 8.6737
c 0
b 0
f 0
1
<?php
2
3
namespace Popy\Calendar\Converter\LeapYearCalculator;
4
5
use Popy\Calendar\Converter\SimpleLeapYearCalculatorInterface;
6
7
/**
8
 * Persian / Solar Hijri leap year calculator.
9
 *
10
 * @link https://en.wikipedia.org/wiki/Solar_Hijri_calendar#Solar_Hijri_algorithmic_calendar
11
 */
12
class Persian implements SimpleLeapYearCalculatorInterface
13
{
14
    /**
15
     * @inheritDoc
16
     */
17
    public function isLeapYear($year)
18
    {
19
        $cycle = $year % 2820;
20
21
        if ($cycle >= 21 * 128) {
22
            $cycle -= 21 * 128;
23
        } else {
24
            $cycle = $cycle % 128;
25
        }
26
27
        if ($cycle >= 29) {
28
            $cycle -= 29;
29
            if ($cycle >= 2*33) {
30
                $cycle -= 2 * 33;
31
            } else {
32
                $cycle = $cycle % 33;
33
            }
34
        }
35
36
        $cycle++;
37
38
        return $cycle > 1 && ($cycle % 4 === 1);
39
    }
40
}
41