Easter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 46
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 23 1
1
<?php
2
3
namespace Andegna\Holiday;
4
5
use Andegna\Converter\FromJdnConverter;
6
use Andegna\DateTimeFactory;
7
use DateTimeZone;
8
9
/**
10
 * Ethiopian Easter.
11
 */
12
class Easter
13
{
14
    /** @var DateTimeZone */
15
    private $dateTimeZone;
16
17
    /**
18
     * Easter constructor.
19
     *
20
     * @param DateTimeZone $dateTimeZone
21
     */
22 41
    public function __construct(DateTimeZone $dateTimeZone = null)
23
    {
24 41
        $this->dateTimeZone = $dateTimeZone;
25 41
    }
26
27
    /**
28
     * Get the easter date of a given Ethiopian year.
29
     *
30
     * @param $year int Ethiopian year
31
     *
32
     * @return \Andegna\DateTime
33
     */
34 41
    public function get(int $year)
35
    {
36
        // convert the Ethiopian year to a Julian year
37
        // ሚያዝያ 1 is just a random day after the Gregorian new year
38 41
        $julian_year = (int) DateTimeFactory::of($year, 8, 1)
39 41
            ->toGregorian()->format('Y');
40
41
        // get the number of days from vernal equinox to the Easter in the given Julian year
42 41
        $days_after = easter_days($julian_year, CAL_EASTER_ALWAYS_JULIAN);
43
44
        // get the JDN of vernal equinox (March 21) in the given Julian year
45 41
        $jdn = juliantojd(3, 21, $julian_year);
46
47
        // add the number of days to Easter
48 41
        $jdn += $days_after;
49
50
        // create a Ethiopian Date to JDN converter
51 41
        $con = new FromJdnConverter($jdn);
52
53
        // create an Ethiopian date from the converter
54 41
        return DateTimeFactory::of($con->getYear(), $con->getMonth(), $con->getDay(),
55 41
            0, 0, 0, $this->dateTimeZone);
56
    }
57
}
58