Russia::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 14
rs 9.9332
cc 1
nc 1
nop 0
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 Yasumi\Holiday;
16
17
/**
18
 * Provider for all holidays in Russia.
19
 *
20
 * @author Gedas Lukošius <[email protected]>
21
 */
22
class Russia extends AbstractProvider
23
{
24
    use CommonHolidays;
25
26
    public const DEFENCE_OF_THE_FATHERLAND_START_YEAR = 1919;
27
28
    public const RUSSIA_DAY_START_YEAR = 1990;
29
30
    public const UNITY_DAY_START_YEAR = 2005;
31
32
    /**
33
     * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
34
     * country or sub-region.
35
     */
36
    public const ID = 'RU';
37
38
    /**
39
     * Initialize holidays for Russia.
40
     *
41
     * @throws \InvalidArgumentException
42
     * @throws \Exception
43
     */
44
    public function initialize(): void
45
    {
46
        $this->timezone = 'Europe/Moscow';
47
48
        // Official
49
        $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
50
        $this->addNewYearsHolidays();
51
        $this->addOrthodoxChristmasDay();
52
        $this->addDefenceOfTheFatherlandDay();
53
        $this->addInternationalWomensDay();
54
        $this->addSpringAndLabourDay();
55
        $this->addVictoryDay();
56
        $this->addRussiaDay();
57
        $this->addUnityDay();
58
    }
59
60
    /**
61
     * @throws \InvalidArgumentException
62
     * @throws \Exception
63
     */
64
    private function addNewYearsHolidays(): void
65
    {
66
        $holidayDays = [2, 3, 4, 5, 6, 8];
67
68
        foreach ($holidayDays as $day) {
69
            $this->addHoliday(new Holiday('newYearHolidaysDay' . $day, [
70
                'en' => 'New Year’s holidays',
71
                'ru' => 'Новогодние каникулы',
72
            ], new \DateTime("{$this->year}-01-{$day}", new \DateTimeZone($this->timezone)), $this->locale));
73
        }
74
    }
75
76
    /**
77
     * @throws \InvalidArgumentException
78
     * @throws \Exception
79
     */
80
    private function addOrthodoxChristmasDay(): void
81
    {
82
        $this->addHoliday(new Holiday('orthodoxChristmasDay', [
83
            'en' => 'Orthodox Christmas Day',
84
            'ru' => 'Рождество',
85
        ], new \DateTime("{$this->year}-01-07", new \DateTimeZone($this->timezone)), $this->locale));
86
    }
87
88
    /**
89
     * @throws \InvalidArgumentException
90
     * @throws \Exception
91
     */
92
    private function addDefenceOfTheFatherlandDay(): void
93
    {
94
        if ($this->year < self::DEFENCE_OF_THE_FATHERLAND_START_YEAR) {
95
            return;
96
        }
97
98
        $this->addHoliday(new Holiday('defenceOfTheFatherlandDay', [
99
            'en' => 'Defence of the Fatherland Day',
100
            'ru' => 'День защитника Отечества',
101
        ], new \DateTime("{$this->year}-02-23", new \DateTimeZone($this->timezone)), $this->locale));
102
    }
103
104
    /**
105
     * @throws \InvalidArgumentException
106
     * @throws \Exception
107
     */
108
    private function addInternationalWomensDay(): void
109
    {
110
        $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale));
111
    }
112
113
    /**
114
     * @throws \InvalidArgumentException
115
     * @throws \Exception
116
     */
117
    private function addSpringAndLabourDay(): void
118
    {
119
        $this->addHoliday(new Holiday('springAndLabourDay', [
120
            'en' => 'Spring and Labour Day',
121
            'ru' => 'Праздник Весны и Труда',
122
        ], new \DateTime("{$this->year}-05-01", new \DateTimeZone($this->timezone)), $this->locale));
123
    }
124
125
    /**
126
     * @throws \InvalidArgumentException
127
     * @throws \Exception
128
     */
129
    private function addVictoryDay(): void
130
    {
131
        $this->addHoliday(new Holiday('victoryDay', [
132
            'en' => 'Victory Day',
133
            'ru' => 'День Победы',
134
        ], new \DateTime("{$this->year}-05-09", new \DateTimeZone($this->timezone)), $this->locale));
135
    }
136
137
    /**
138
     * @throws \InvalidArgumentException
139
     * @throws \Exception
140
     */
141
    private function addRussiaDay(): void
142
    {
143
        if ($this->year < self::RUSSIA_DAY_START_YEAR) {
144
            return;
145
        }
146
147
        $this->addHoliday(new Holiday('russiaDay', [
148
            'en' => 'Russia Day',
149
            'ru' => 'День России',
150
        ], new \DateTime("{$this->year}-06-12", new \DateTimeZone($this->timezone)), $this->locale));
151
    }
152
153
    /**
154
     * @throws \InvalidArgumentException
155
     * @throws \Exception
156
     */
157
    private function addUnityDay(): void
158
    {
159
        if ($this->year < self::UNITY_DAY_START_YEAR) {
160
            return;
161
        }
162
163
        $this->addHoliday(new Holiday('unityDay', [
164
            'en' => 'Unity Day',
165
            'ru' => 'День народного единства',
166
        ], new \DateTime("{$this->year}-11-04", new \DateTimeZone($this->timezone)), $this->locale));
167
    }
168
}
169