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

StoryPointBurndown   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 163
Duplicated Lines 1.84 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 88.89%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 20
c 2
b 1
f 1
lcom 1
cbo 1
dl 3
loc 163
ccs 48
cts 54
cp 0.8889
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getAverageSP() 0 4 1
A setAverageSP() 0 4 1
A getDoneSP() 0 4 1
A setDoneSP() 0 4 1
A getTotalSP() 0 4 1
A setTotalSP() 0 4 1
A getSprint() 0 4 1
A setSprint() 0 4 1
A formatDate() 0 4 1
A getRealBurndown() 0 12 2
C getTheoreticalBurndown() 3 23 7
A generate() 0 7 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 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
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

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...
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $doneSP of type double is incompatible with the declared type array of property $doneSP.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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)) {
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...
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