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 |
|
|
|
|
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)) { |
|
|
|
|
137
|
3 |
|
continue; |
138
|
|
|
} |
139
|
3 |
|
++$total; |
140
|
|
|
} |
141
|
|
|
|
142
|
3 |
|
return $total; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
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.