Persian   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B isLeapYear() 0 22 5
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