Completed
Push — master ( 4e7071...99053a )
by Sébastien
02:43
created

Sprint   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 137
Duplicated Lines 2.19 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 87.8%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 19
c 2
b 1
f 1
lcom 1
cbo 0
dl 3
loc 137
ccs 36
cts 41
cp 0.878
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getStart() 0 4 1
A getDuration() 0 4 1
A setStart() 0 4 1
A setDuration() 0 4 1
A getEnd() 0 10 3
A getSprintDays() 0 18 3
A getNextDayInSprint() 0 15 3
B getTotalWorkDays() 3 18 6

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 TrelloBurndown\Model;
4
5
/**
6
 * Class Sprint.
7
 */
8
class Sprint
9
{
10
    /**
11
     * @var \DateTime
12
     */
13
    private $start;
14
15
    /**
16
     * @var \DateInterval
17
     */
18
    private $duration;
19
20
    /**
21
     * @const String
22
     */
23
    const INTERVAL = 'P1D';
24
25
    /**
26
     * @return \DateTime
27
     */
28 7
    public function getStart()
29
    {
30 7
        return $this->start;
31
    }
32
33
    /**
34
     * @return \DateInterval
35
     */
36 1
    public function getDuration()
37
    {
38 1
        return $this->duration;
39
    }
40
41
    /**
42
     * @param \DateTime $start
43
     */
44 12
    public function setStart(\DateTime $start)
45
    {
46 12
        $this->start = $start;
47 12
    }
48
49
    /**
50
     * @param \DateInterval $duration
51
     */
52 12
    public function setDuration(\DateInterval $duration)
53
    {
54 12
        $this->duration = $duration;
55 12
    }
56
57
    /**
58
     * Calculate the end of sprint from start and duration.
59
     *
60
     * @return \DateTime|null
61
     */
62 8
    public function getEnd()
63
    {
64 8
        if ($this->start instanceof \DateTime && $this->duration instanceof \DateInterval) {
65 8
            $end = clone $this->start;
66
67 8
            return $end->add($this->duration);
68
        }
69
70
        return null;
71
    }
72
73
    /**
74
     * Get all days in the sprint from start date
75
     * and during duration.
76
     *
77
     * @return \DatePeriod|null
78
     */
79 7
    public function getSprintDays()
80
    {
81 7
        if ($this->start instanceof \DateTime && $this->duration instanceof \DateInterval) {
82 7
            $interval = new \DateInterval(self::INTERVAL);
83
84 7
            $end = $this->getEnd();
85
86 7
            $firstDay = clone $this->start;
87
88 7
            return new \DatePeriod(
89 7
                $firstDay->add($interval),
90
                $interval,
91
                $end
92
            );
93
        }
94
95
        return null;
96
    }
97
98
    /**
99
     * Calculate the next day in the sprint.
100
     *
101
     * @return \DateTime
102
     */
103 5
    public function getNextDayInSprint()
104
    {
105 5
        $today = new \DateTime();
106 5
        $today->setTime(0, 0, 0);
107
108 5
        if ($today->format('N') == 5) {
109
            return $today->modify('+3 days');
110
        }
111
112 5
        if ($today->format('N') == 6) {
113
            return $today->modify('+2 days');
114
        }
115
116 5
        return $today->modify('+1 days');
117
    }
118
119
    /**
120
     * Calculate the total work days in the sprint.
121
     * This function does not return week-end days but
122
     * return non-work-days such as christmas.
123
     *
124
     * @return int | null
0 ignored issues
show
Documentation introduced by
Should the return type not be null|integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
125
     */
126 3
    public function getTotalWorkDays()
127
    {
128 3
        $days = $this->getSprintDays();
129 3
        $total = 0;
130
131 3
        if(!$days instanceof \DatePeriod) {
132
            return null;
133
        }
134
135 3
        foreach ($days as $day) {
136 3 View Code Duplication
            if ($day instanceof \DateTime && ($day->format('N') == 6 || $day->format('N') == 7)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
137 3
                continue;
138
            }
139 3
            ++$total;
140
        }
141
142 3
        return $total;
143
    }
144
}
145