|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TrelloBurndown\Model; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class StoryPointBurndown. |
|
7
|
|
|
*/ |
|
8
|
|
|
class StoryPointBurndown |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var float |
|
12
|
|
|
*/ |
|
13
|
|
|
private $averageSP; |
|
14
|
|
|
/** |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
private $doneSP; |
|
18
|
|
|
/** |
|
19
|
|
|
* @var float |
|
20
|
|
|
*/ |
|
21
|
|
|
private $totalSP; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var Sprint |
|
24
|
|
|
*/ |
|
25
|
|
|
private $sprint; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private static $dateFormat = 'Y-m-d'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* StoryPointBurndown constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param Sprint $sprint |
|
36
|
|
|
* @param float $totalSP |
|
37
|
|
|
* @param array $doneSP |
|
38
|
|
|
* @param float $averageSP |
|
39
|
|
|
*/ |
|
40
|
5 |
|
public function __construct(Sprint $sprint, float $totalSP, array $doneSP, float $averageSP) |
|
41
|
|
|
{ |
|
42
|
5 |
|
$this->sprint = $sprint; |
|
43
|
5 |
|
$this->totalSP = $totalSP; |
|
44
|
5 |
|
$this->doneSP = $doneSP; |
|
45
|
5 |
|
$this->averageSP = $averageSP; |
|
46
|
5 |
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return float |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function getAverageSP() |
|
52
|
|
|
{ |
|
53
|
1 |
|
return $this->averageSP; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param float $averageSP |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function setAverageSP($averageSP) |
|
60
|
|
|
{ |
|
61
|
1 |
|
$this->averageSP = $averageSP; |
|
62
|
1 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return float |
|
|
|
|
|
|
66
|
|
|
*/ |
|
67
|
1 |
|
public function getDoneSP() |
|
68
|
|
|
{ |
|
69
|
1 |
|
return $this->doneSP; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param float $doneSP |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function setDoneSP($doneSP) |
|
76
|
|
|
{ |
|
77
|
1 |
|
$this->doneSP = $doneSP; |
|
|
|
|
|
|
78
|
1 |
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return float |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function getTotalSP() |
|
84
|
|
|
{ |
|
85
|
1 |
|
return $this->totalSP; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param float $totalSP |
|
90
|
|
|
*/ |
|
91
|
1 |
|
public function setTotalSP($totalSP) |
|
92
|
|
|
{ |
|
93
|
1 |
|
$this->totalSP = $totalSP; |
|
94
|
1 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return Sprint |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getSprint() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->sprint; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param Sprint $sprint |
|
106
|
|
|
*/ |
|
107
|
|
|
public function setSprint($sprint) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->sprint = $sprint; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
3 |
|
public function formatDate(\DateTime $date) |
|
113
|
|
|
{ |
|
114
|
3 |
|
return $date->format(self::$dateFormat); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return array |
|
119
|
|
|
*/ |
|
120
|
2 |
|
public function getRealBurndown() |
|
121
|
|
|
{ |
|
122
|
2 |
|
$realBurndown = []; |
|
123
|
2 |
|
$total = $this->totalSP; |
|
124
|
2 |
|
$realBurndown[$this->formatDate($this->sprint->getStart())] = $total; |
|
125
|
2 |
|
foreach ($this->doneSP as $sp) { |
|
126
|
2 |
|
$total = $total - $sp['count']; |
|
127
|
2 |
|
$realBurndown[$this->formatDate($sp['date'])] = $total; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
2 |
|
return $realBurndown; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return array|null |
|
135
|
|
|
*/ |
|
136
|
2 |
|
public function getTheoreticalBurndown() |
|
137
|
|
|
{ |
|
138
|
2 |
|
$theoreticalBurndown = []; |
|
139
|
2 |
|
$theoreticalBurndown[$this->sprint->getStart()->format('Y-m-d')] = $this->totalSP; |
|
140
|
|
|
|
|
141
|
2 |
|
$sprintDays = $this->sprint->getSprintDays(); |
|
142
|
2 |
|
if (!$sprintDays instanceof \DatePeriod) { |
|
143
|
|
|
return; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
2 |
|
foreach ($sprintDays as $day) { |
|
147
|
2 |
View Code Duplication |
if ($day instanceof \DateTime && ($day->format('N') == 6 || $day->format('N') == 7)) { |
|
|
|
|
|
|
148
|
2 |
|
continue; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
2 |
|
$rest = end($theoreticalBurndown) != false ? end($theoreticalBurndown) : $this->totalSP; |
|
152
|
2 |
|
$formatedDate = $this->formatDate($day); |
|
153
|
2 |
|
$doneSP = $rest - $this->averageSP; |
|
154
|
2 |
|
$theoreticalBurndown[$formatedDate] = round($doneSP, 2); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
2 |
|
return $theoreticalBurndown; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return array |
|
162
|
|
|
*/ |
|
163
|
1 |
|
public function generate() |
|
164
|
|
|
{ |
|
165
|
1 |
|
$real = $this->getRealBurndown(); |
|
166
|
1 |
|
$ideal = $this->getTheoreticalBurndown(); |
|
167
|
|
|
|
|
168
|
1 |
|
return ['real' => $real, 'theorical' => $ideal]; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.