Denmark::prepareHolidays()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 105
Code Lines 66

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 66
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 105
ccs 66
cts 66
cp 1
rs 8.2857
cc 1
eloc 66
nc 1
nop 1
crap 1

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
2
3
/*
4
 * This file is part of the Holiday Library.
5
 *
6
 * (c) Michał Mańko <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Michalmanko\Holiday\Provider;
13
14
use ArrayObject;
15
use Michalmanko\Holiday\Holiday;
16
17
/**
18
 * Danish Holidays Provider.
19
 */
20
class Denmark extends AbstractProvider
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 12
    protected function prepareHolidays($year)
26
    {
27 12
        $data = new ArrayObject();
28
29
        // New year's day
30 12
        $data->append($this->createHoliday(
31 12
            'Nytårsdag',
32 12
            $year . '-01-01',
33
            Holiday::TYPE_HOLIDAY
34 12
        ));
35
36
        // Easter Sunday
37 12
        $easter = $this->createHoliday(
38 12
            'Påskedag',
39 12
            $this->getEaster($year),
40
            Holiday::TYPE_HOLIDAY
41 12
        );
42 12
        $data->append($easter);
43
44
        // Maundy Thursday
45 12
        $easterThursday = $this->createHoliday(
46 12
            'Skærtorsdag',
47 12
            $easter,
48
            Holiday::TYPE_HOLIDAY
49 12
        );
50 12
        $easterThursday->modify('-3 days');
51 12
        $data->append($easterThursday);
52
53
        // Good Friday
54 12
        $easterFriday = $this->createHoliday(
55 12
            'Langfredag',
56 12
            $easter,
57
            Holiday::TYPE_HOLIDAY
58 12
        );
59 12
        $easterFriday->modify('-2 days');
60 12
        $data->append($easterFriday);
61
62
        // Easter Monday
63 12
        $easterMonday = $this->createHoliday(
64 12
            '2. Påskedag',
65 12
            $easter,
66
            Holiday::TYPE_HOLIDAY
67 12
        );
68 12
        $easterMonday->modify('+1 day');
69 12
        $data->append($easterMonday);
70
71
        // Prayer day
72 12
        $prayerDay = $this->createHoliday(
73 12
            'Store bededag',
74 12
            $easter,
75
            Holiday::TYPE_HOLIDAY
76 12
        );
77 12
        $prayerDay->modify('+3 weeks +5 days');
78 12
        $data->append($prayerDay);
79
80
        // Ascension Day
81 12
        $ascensionDay = $this->createHoliday(
82 12
            'Kristi himmelfartsdag',
83 12
            $easter,
84
            Holiday::TYPE_HOLIDAY
85 12
        );
86 12
        $ascensionDay->modify('+39 days');
87 12
        $data->append($ascensionDay);
88
89
        // Pentecost day
90 12
        $pentecostDay = $this->createHoliday(
91 12
            'Pinsedag',
92 12
            $easter,
93
            Holiday::TYPE_HOLIDAY
94 12
        );
95 12
        $pentecostDay->modify('+49 days');
96 12
        $data->append($pentecostDay);
97
98
        // 2. Pentecost day
99 12
        $pentecostDay2 = $this->createHoliday(
100 12
            '2. Pinsedag',
101 12
            $pentecostDay,
102
            Holiday::TYPE_HOLIDAY
103 12
        );
104 12
        $pentecostDay2->modify('+1 day');
105 12
        $data->append($pentecostDay2);
106
107
        // Constitution day
108 12
        $data->append($this->createHoliday(
109 12
            'Grundlovsdag',
110 12
            $year . '-06-5',
111
            Holiday::TYPE_HOLIDAY
112 12
        ));
113
114
        // Christmas day
115 12
        $data->append($this->createHoliday(
116 12
            'Juledag',
117 12
            $year . '-12-25',
118
            Holiday::TYPE_HOLIDAY
119 12
        ));
120
121
        // Boxing Day
122 12
        $data->append($this->createHoliday(
123 12
            '2. Juledag',
124 12
            $year . '-12-26',
125
            Holiday::TYPE_HOLIDAY
126 12
        ));
127
128 12
        return $data->getArrayCopy();
129
    }
130
}
131