Completed
Pull Request — master (#6)
by steef
08:13
created

GoodFriday   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 130
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 130
loc 130
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 21 21 2
A calculateGNumber() 4 4 1
A calculateCNumber() 4 4 1
A calculateXNumber() 4 4 1
A calculateYNumber() 4 4 1
A calculateZNumber() 4 4 1
A calculateENumber() 10 10 4
A calculateNNumber() 10 10 2
A calculatePNumber() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Stefanius\SpecialDates\CommonDates;
4
5
use Stefanius\SpecialDates\SDK\AbstractSpecialDate;
6
7
/**
8
 * Class FirstEasterDay
9
 * see: https://nl.wikipedia.org/wiki/Paas-_en_pinksterdatum#Methode_van_Gauss
10
 *
11
 * @package Stefanius\SpecialDates\CommonDates
12
 */
13 View Code Duplication
class GoodFriday extends AbstractSpecialDate
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    protected function generate()
16
    {
17
        $this->bankHoliday = true;
18
        $this->description = 'Goede vrijdag';
19
20
        $g = $this->calculateGNumber();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $g. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
21
        $c = $this->calculateCNumber();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
22
        $x = $this->calculateXNumber($c);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $x. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
23
        $y = $this->calculateYNumber($c);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $y. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
24
        $z = $this->calculateZNumber($x);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $z. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
25
        $e = $this->calculateENumber($g, $y, $x);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $e. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
26
        $n = $this->calculateNNumber($e);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $n. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
27
        $p = $this->calculatePNumber($z, $n);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $p. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
28
29
        if ($p > 31) {
30
            $p -= 31;
31
            $this->setupDateTimeObjects($this->generateDateTime($this->year, 4, $p)->modify('-2 days'));
32
        } else {
33
            $this->setupDateTimeObjects($this->generateDateTime($this->year, 3, $p)->modify('-2 days'));
34
        }
35
    }
36
37
    /**
38
     * Deel het jaartal door 19, neem de rest, en tel er 1 bij op (zoals Dionysius). Noem dit getal G. Voor het jaar 1991 geldt G = 16.
39
     *
40
     * @return int
41
     */
42
    protected function calculateGNumber()
43
    {
44
        return ($this->year % 19) + 1;
45
    }
46
47
    /**
48
     * Geheeldeel het jaartal door 100 en tel daar 1 bij op. Noem dit getal C. Voor het jaar 1991 geldt C = 20.
49
     *
50
     * @return int
51
     */
52
    protected function calculateCNumber()
53
    {
54
        return (int)floor($this->year / 100) + 1;
55
    }
56
57
    /**
58
     * Vermenigvuldig C met 3, geheeldeel het resultaat door 4 en trek er 12 van af. Noem dit getal X. Voor de twintigste en eenentwintigste eeuw geldt X = 3.
59
     *
60
     * @param int $c
61
     * @return float
62
     */
63
    protected function calculateXNumber(int $c)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
64
    {
65
        return (($c * 3) / 4) - 12;
66
    }
67
68
    /**
69
     *  Neem 8 maal C, tel er 5 bij op, geheeldeel dit door 25 en trek er 5 vanaf. Noem dit getal Y. Voor de twintigste en eenentwintigste eeuw geldt: Y = 1.
70
     *
71
     * @param int $c
72
     * @return float
73
     */
74
    protected function calculateYNumber(int $c)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
75
    {
76
        return ((($c * 8) + 4) / 25) - 5;
77
    }
78
79
    /**
80
     * Vermenigvuldig het jaartal met 5, geheeldeel de uitkomst door 4, trek er X en 10 vanaf, en noem dit getal Z. Voor 1991 geldt: Z = 2475.
81
     *
82
     * @param int $x
83
     * @return float
84
     */
85
    protected function calculateZNumber(int $x)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $x. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
86
    {
87
        return ((($this->year * 5) / 4) - $x) - 10;
88
    }
89
90
    /**
91
     * 11 maal G + 20 + Y. Trek daarvan X af, geheeldeel het resultaat door 30 en noem de rest E. Als E gelijk is aan 24, of als E gelijk is aan 25 en het gulden getal is groter dan 11, tel dan 1 bij E op. De Epacta voor 1991 is 14.
92
     *
93
     * @param int $x
94
     * @return float
95
     */
96
    protected function calculateENumber(int $g, int $y, int $x)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $g. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $y. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $x. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
97
    {
98
        $e = (((($g * 11) + 20) + $y) - $x) % 30;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $e. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
99
100
        if (($e === 24) || ($e === 25 && $g > 11)) {
101
            $e++;
102
        }
103
104
        return $e;
105
    }
106
107
    /**
108
     * Trek E af van 44. Noem dit getal N. Als N kleiner is dan 21, tel er dan 30 bij op. Voor 1991 geldt: N = 30
109
     *
110
     * @param int $e
111
     *
112
     * @return int
113
     */
114
    protected function calculateNNumber(int $e)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $e. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
115
    {
116
        $n = 44 - $e;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $n. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
117
118
        if ($n < 21) {
119
            $n += 30;
120
        }
121
122
        return $n;
123
    }
124
125
    /**
126
     * Tel Z en N op. Geheeldeel het resultaat door 7 en trek de rest af van N+7. Noem dit getal P. Voor 1991 geldt: P = 31.
127
     *
128
     * @param int $z
129
     * @param int $n
130
     * @return int
131
     */
132
    protected function calculatePNumber(int $z, int $n)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $z. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $n. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
133
    {
134
        return ($n + 7) - (($z + $n) % 7);
135
    }
136
137
    /**
138
139
140
    Paasdatum: Als P groter is dan 31, trek er dan 31 vanaf, en de paasdatum valt in april. Anders is de paasdag P in maart. Zo wordt voor 1991 gevonden 31 maart.
141
     */
142
}
143