Brazil::initialize()   B
last analyzed

Complexity

Conditions 7
Paths 64

Size

Total Lines 131
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 53
c 0
b 0
f 0
dl 0
loc 131
rs 8.0921
cc 7
nc 64
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 DateInterval;
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 Brazil.
23
 */
24
class Brazil 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 = 'BR';
33
34
    /**
35
     * Initialize holidays for Brazil.
36
     *
37
     * @throws InvalidDateException
38
     * @throws \InvalidArgumentException
39
     * @throws UnknownLocaleException
40
     * @throws \Exception
41
     */
42
    public function initialize(): void
43
    {
44
        $this->timezone = 'America/Fortaleza';
45
46
        // Add common holidays
47
        $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
48
        $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
49
50
        // Add Christian holidays
51
        $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
52
        $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
53
        $this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
54
        $this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
55
        $this->addHoliday($this->ashWednesday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
56
57
        /**
58
         * Carnaval
59
         *
60
         * Carnaval is the biggest popular festival of country. The festival it happens during 4 days and the last day above
61
         * the wednesday of ashes (initiation of lent).
62
         *
63
         * @link https://en.wikipedia.org/wiki/Brazilian_Carnival
64
         */
65
        if ($this->year >= 1700) {
66
            $easter = $this->calculateEaster($this->year, $this->timezone);
67
68
            $carnavalMonday = clone $easter;
69
            $this->addHoliday(new Holiday(
70
                'carnavalMonday',
71
                ['pt' => 'Segunda-feira de Carnaval'],
72
                $carnavalMonday->sub(new DateInterval('P48D')),
73
                $this->locale,
74
                Holiday::TYPE_OBSERVANCE
75
            ));
76
77
            $carnavalTuesday = clone $easter;
78
            $this->addHoliday(new Holiday(
79
                'carnavalTuesday',
80
                ['pt' => 'Terça-feira de Carnaval'],
81
                $carnavalTuesday->sub(new DateInterval('P47D')),
82
                $this->locale,
83
                Holiday::TYPE_OBSERVANCE
84
            ));
85
        }
86
87
        /**
88
         * Tiradentes Day
89
         *
90
         * Tiradentes Day is a the Brazilian national holidays. Is the a tribute to national Brazilian hero Joaquim José
91
         * da Silva Xavier, martyr of Inconfidência Mineira. Is celebrated on 21 Abril, because the execution of
92
         * Tiradentes got in the day, in 1792.
93
         *
94
         * @link https://en.wikipedia.org/wiki/Tiradentes
95
         */
96
        if ($this->year >= 1792) {
97
            $this->addHoliday(new Holiday(
98
                'tiradentesDay',
99
                ['pt' => 'Dia de Tiradentes'],
100
                new DateTime("$this->year-04-21", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
101
                $this->locale
102
            ));
103
        }
104
105
        /**
106
         * Independence Day
107
         *
108
         * The Homeland Day is a national holiday of Brazilian homeland celebrated on 7 September. The date is
109
         * celebrated the independence declaration of Brazil to Portuguese empire on 7 September 1822.
110
         *
111
         * @link https://en.wikipedia.org/wiki/Independence_of_Brazil
112
         */
113
        if ($this->year >= 1822) {
114
            $this->addHoliday(new Holiday(
115
                'independenceDay',
116
                ['pt' => 'Dia da Independência do Brasil'],
117
                new DateTime("$this->year-09-07", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
118
                $this->locale
119
            ));
120
        }
121
122
        /**
123
         * Our Lady of Aparecida Day
124
         *
125
         * Our Lady of Conceição Aparecida, popularly called Our Lady Aparecida, Brazil's patroness. She is
126
         * venerated in Catholic Church. Our Lady Aparecida is represented like a little image of Virgen Maria,
127
         * currently in Basílica of Our Lady Aparecida, localized in São Paulo.
128
         *
129
         * The event is celebrated on 12 October, a national holiday in Brazil since 1980.
130
         *
131
         * @link https://en.wikipedia.org/wiki/Our_Lady_of_Aparecida
132
         */
133
        if ($this->year >= 1980) {
134
            $this->addHoliday(new Holiday(
135
                'ourLadyOfAparecidaDay',
136
                ['pt' => 'Dia de Nossa Senhora Aparecida'],
137
                new DateTime("$this->year-10-12", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
138
                $this->locale
139
            ));
140
        }
141
142
        /**
143
         * All Souls Day
144
         *
145
         * The All Souls day (known like Deads Day in Mexico), is celebrated for Catholic Church on 2 November.
146
         *
147
         * @link http://www.johninbrazil.org/all-souls-day-o-dia-dos-finados/
148
         */
149
        if ($this->year >= 1300) {
150
            $this->addHoliday(new Holiday(
151
                'allSoulsDay',
152
                [],
153
                new DateTime("$this->year-11-02", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
154
                $this->locale
155
            ));
156
        }
157
158
        /**
159
         * Proclamation of Republic Day
160
         *
161
         * The Brazilian Proclamation of Republic was an act relevant military politic it happened on 15 November 1889
162
         * that initiated the build federative presidential of govern in Brazil, downed the monarchy constitutional
163
         * parlamentary of Brazil's Empire.
164
         *
165
         * @link https://en.wikipedia.org/wiki/Proclamation_of_the_Republic_(Brazil)
166
         */
167
        if ($this->year >= 1889) {
168
            $this->addHoliday(new Holiday(
169
                'proclamationOfRepublicDay',
170
                ['pt' => 'Dia da Proclamação da República'],
171
                new DateTime("$this->year-11-15", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
172
                $this->locale
173
            ));
174
        }
175
    }
176
}
177