Italy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 28
dl 0
loc 94
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 21 1
A calculateLiberationDay() 0 8 2
A calculateRepublicDay() 0 8 2
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the Yasumi package.
4
 *
5
 * Copyright (c) 2015 - 2020 AzuyaLabs
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Sacha Telgenhof <[email protected]>
11
 */
12
13
namespace Yasumi\Provider;
14
15
use DateTime;
16
use Yasumi\Exception\InvalidDateException;
17
use Yasumi\Exception\UnknownLocaleException;
18
use Yasumi\Holiday;
19
20
/**
21
 * Provider for all holidays in Italy.
22
 */
23
class Italy extends AbstractProvider
24
{
25
    use CommonHolidays, ChristianHolidays;
26
27
    /**
28
     * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
29
     * country or sub-region.
30
     */
31
    public const ID = 'IT';
32
33
    /**
34
     * Initialize holidays for Italy.
35
     *
36
     * @throws InvalidDateException
37
     * @throws \InvalidArgumentException
38
     * @throws UnknownLocaleException
39
     * @throws \Exception
40
     */
41
    public function initialize(): void
42
    {
43
        $this->timezone = 'Europe/Rome';
44
45
        // Add common holidays
46
        $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
47
48
        // Add Christian holidays
49
        $this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale));
50
        $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale));
51
        $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale));
52
        $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
53
        $this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale));
54
        $this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale));
55
        $this->addHoliday($this->immaculateConception($this->year, $this->timezone, $this->locale));
56
        $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
57
        $this->addHoliday($this->stStephensDay($this->year, $this->timezone, $this->locale));
58
59
        // Calculate other holidays
60
        $this->calculateLiberationDay();
61
        $this->calculateRepublicDay();
62
    }
63
64
    /**
65
     * Liberation Day.
66
     *
67
     * Italy's Liberation Day (Festa della Liberazione), also known as the Anniversary of the Liberation
68
     * (Anniversario della liberazione d'Italia), Anniversary of the Resistance (anniversario della Resistenza), or
69
     * simply April 25 is a national Italian holiday commemorating the end of the second world war and the end of
70
     * Nazi occupation of the country. On May 27, 1949, bill 260 made the anniversary a permanent, annual national
71
     * holiday.
72
     *
73
     * @link https://en.wikipedia.org/wiki/Liberation_Day_%28Italy%29
74
     *
75
     * @throws InvalidDateException
76
     * @throws \InvalidArgumentException
77
     * @throws UnknownLocaleException
78
     * @throws \Exception
79
     * @throws \Exception
80
     */
81
    private function calculateLiberationDay(): void
82
    {
83
        if ($this->year >= 1949) {
84
            $this->addHoliday(new Holiday(
85
                'liberationDay',
86
                ['it' => 'Festa della Liberazione'],
87
                new DateTime("$this->year-4-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
88
                $this->locale
89
            ));
90
        }
91
    }
92
93
    /**
94
     * Class containing tests for Republic Day in Italy.
95
     *
96
     * Festa della Repubblica (in English, Republic Day) is the Italian National Day and Republic Day, which is
97
     * celebrated on 2 June each year. The day commemorates the institutional referendum held by universal suffrage
98
     * in 1946, in which the Italian people were called to the polls to decide on the form of government, following
99
     * the Second World War and the fall of Fascism.
100
     *
101
     * @link https://en.wikipedia.org/wiki/Festa_della_Repubblica
102
     *
103
     * @throws InvalidDateException
104
     * @throws \InvalidArgumentException
105
     * @throws UnknownLocaleException
106
     * @throws \Exception
107
     * @throws \Exception
108
     */
109
    private function calculateRepublicDay(): void
110
    {
111
        if ($this->year >= 1946) {
112
            $this->addHoliday(new Holiday(
113
                'republicDay',
114
                ['it' => 'Festa della Repubblica'],
115
                new DateTime("$this->year-6-2", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
116
                $this->locale
117
            ));
118
        }
119
    }
120
}
121