Sprint   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.37%

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 17
c 3
b 1
f 2
lcom 1
cbo 1
dl 0
loc 138
ccs 35
cts 41
cp 0.8537
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 getTotalWorkDays() 0 18 4
A getNextDayInSprint() 0 15 3
1
<?php
2
3
namespace TrelloBurndown\Model;
4
5
use TrelloBurndown\Helper\DateHelper;
6
7
/**
8
 * Class Sprint.
9
 */
10
class Sprint
11
{
12
    use DateHelper;
13
    /**
14
     * @var \DateTime
15
     */
16
    private $start;
17
18
    /**
19
     * @var \DateInterval
20
     */
21
    private $duration;
22
23
    /**
24
     * @const String
25
     */
26
    const INTERVAL = 'P1D';
27
28
    /**
29
     * @return \DateTime
30
     */
31 3
    public function getStart()
32
    {
33 3
        return $this->start;
34
    }
35
36
    /**
37
     * @return \DateInterval
38
     */
39 1
    public function getDuration()
40
    {
41 1
        return $this->duration;
42
    }
43
44
    /**
45
     * @param \DateTime $start
46
     */
47 8
    public function setStart(\DateTime $start)
48
    {
49 8
        $this->start = $start;
50 8
    }
51
52
    /**
53
     * @param \DateInterval $duration
54
     */
55 8
    public function setDuration(\DateInterval $duration)
56
    {
57 8
        $this->duration = $duration;
58 8
    }
59
60
    /**
61
     * Calculate the end of sprint from start and duration.
62
     *
63
     * @return \DateTime|null
64
     */
65 4
    public function getEnd()
66
    {
67 4
        if ($this->start instanceof \DateTime && $this->duration instanceof \DateInterval) {
68 4
            $end = clone $this->start;
69
70 4
            return $end->add($this->duration);
71
        }
72
73
        return;
74
    }
75
76
    /**
77
     * Get all days in the sprint from start date
78
     * and during duration.
79
     *
80
     * @return \DatePeriod|null
81
     */
82 3
    public function getSprintDays()
83
    {
84 3
        if ($this->start instanceof \DateTime && $this->duration instanceof \DateInterval) {
85 3
            $interval = new \DateInterval(self::INTERVAL);
86
87 3
            $end = $this->getEnd();
88
89 3
            $firstDay = clone $this->start;
90
91 3
            return new \DatePeriod(
92 3
                $firstDay->add($interval),
93
                $interval,
94
                $end
95
            );
96
        }
97
98
        return;
99
    }
100
101
    /**
102
     * Calculate the next day in the sprint.
103
     *
104
     * @return \DateTime
105
     */
106 1
    public function getNextDayInSprint()
107
    {
108 1
        $today = new \DateTime();
109 1
        $today->setTime(0, 0, 0);
110
111 1
        if ($today->format('N') == 5) {
112 1
            return $today->modify('+3 days');
113
        }
114
115
        if ($today->format('N') == 6) {
116
            return $today->modify('+2 days');
117
        }
118
119
        return $today->modify('+1 days');
120
    }
121
122
    /**
123
     * Calculate the total work days in the sprint.
124
     * This function does not return week-end days but
125
     * return non-work-days such as christmas.
126
     *
127
     * @return null|int
128
     */
129 1
    public function getTotalWorkDays()
130
    {
131 1
        $days = $this->getSprintDays();
132 1
        $total = 0;
133
134 1
        if (!$days instanceof \DatePeriod) {
135
            return;
136
        }
137
138 1
        foreach ($days as $day) {
139 1
            if ($this->isWeekend($day)) {
140 1
                continue;
141
            }
142 1
            ++$total;
143
        }
144
145 1
        return $total;
146
    }
147
}
148