Germany   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 22
c 1
b 0
f 0
dl 0
loc 69
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A calculateGermanUnityDay() 0 8 2
A initialize() 0 23 2
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the Yasumi package.
5
 *
6
 * Copyright (c) 2015 - 2020 AzuyaLabs
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @author Sacha Telgenhof <[email protected]>
12
 */
13
14
namespace Yasumi\Provider;
15
16
use DateTime;
17
use Yasumi\Exception\InvalidDateException;
18
use Yasumi\Exception\UnknownLocaleException;
19
use Yasumi\Holiday;
20
21
/**
22
 * Provider for all holidays in Germany.
23
 */
24
class Germany extends AbstractProvider
25
{
26
    use CommonHolidays, ChristianHolidays;
27
28
    /**
29
     * Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
30
     * country or sub-region.
31
     */
32
    public const ID = 'DE';
33
34
    /**
35
     * Initialize holidays for Germany.
36
     *
37
     * @throws InvalidDateException
38
     * @throws \InvalidArgumentException
39
     * @throws UnknownLocaleException
40
     * @throws \Exception
41
     */
42
    public function initialize(): void
43
    {
44
        $this->timezone = 'Europe/Berlin';
45
46
        // Add common holidays
47
        $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
48
        $this->addHoliday($this->newYearsEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OTHER));
49
50
        // Add common Christian holidays (common in Germany)
51
        $this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale));
52
        $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
53
        $this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale));
54
        $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale));
55
        $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
56
        $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale));
57
        $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale));
58
59
        // Calculate other holidays
60
        $this->calculateGermanUnityDay();
61
62
        // Note: all German states have agreed this to be a nationwide holiday in 2017 to celebrate the 500th anniversary.
63
        if (2017 === $this->year) {
64
            $this->addHoliday($this->reformationDay($this->year, $this->timezone, $this->locale));
65
        }
66
    }
67
68
    /**
69
     * German Unity Day.
70
     *
71
     * The Day of German Unity (German: Tag der Deutschen Einheit) is the national day of Germany, celebrated on
72
     * 3 October as a public holiday. It commemorates the anniversary of German reunification in 1990, when the
73
     * goal of a united Germany that originated in the middle of the 19th century, was fulfilled again. Therefore,
74
     * the name addresses neither the re-union nor the union, but the unity of Germany. The Day of German Unity on
75
     * 3 October has been the German national holiday since 1990, when the reunification was formally completed. It
76
     * is a legal holiday for the Federal Republic of Germany.
77
     *
78
     * @link https://en.wikipedia.org/wiki/German_Unity_Day
79
     *
80
     * @throws InvalidDateException
81
     * @throws \InvalidArgumentException
82
     * @throws UnknownLocaleException
83
     * @throws \Exception
84
     */
85
    private function calculateGermanUnityDay(): void
86
    {
87
        if ($this->year >= 1990) {
88
            $this->addHoliday(new Holiday(
89
                'germanUnityDay',
90
                ['de' => 'Tag der Deutschen Einheit'],
91
                new DateTime($this->year . '-10-3', new \DateTimeZone($this->timezone)),
92
                $this->locale
93
            ));
94
        }
95
    }
96
}
97