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 |
||
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) |
|
47 | |||
48 | /** |
||
49 | * @return float |
||
50 | */ |
||
51 | 1 | public function getAverageSP() |
|
55 | |||
56 | /** |
||
57 | * @param float $averageSP |
||
58 | */ |
||
59 | 1 | public function setAverageSP($averageSP) |
|
63 | |||
64 | /** |
||
65 | * @return float |
||
|
|||
66 | */ |
||
67 | 1 | public function getDoneSP() |
|
71 | |||
72 | /** |
||
73 | * @param float $doneSP |
||
74 | */ |
||
75 | 1 | public function setDoneSP($doneSP) |
|
79 | |||
80 | /** |
||
81 | * @return float |
||
82 | */ |
||
83 | 1 | public function getTotalSP() |
|
87 | |||
88 | /** |
||
89 | * @param float $totalSP |
||
90 | */ |
||
91 | 1 | public function setTotalSP($totalSP) |
|
95 | |||
96 | /** |
||
97 | * @return Sprint |
||
98 | */ |
||
99 | public function getSprint() |
||
103 | |||
104 | /** |
||
105 | * @param Sprint $sprint |
||
106 | */ |
||
107 | public function setSprint($sprint) |
||
111 | |||
112 | 3 | public function formatDate(\DateTime $date) |
|
116 | |||
117 | /** |
||
118 | * @return array |
||
119 | */ |
||
120 | 2 | public function getRealBurndown() |
|
132 | |||
133 | /** |
||
134 | * @return array|null |
||
135 | */ |
||
136 | 2 | public function getTheoreticalBurndown() |
|
159 | |||
160 | /** |
||
161 | * @return array |
||
162 | */ |
||
163 | 1 | public function generate() |
|
170 | } |
||
171 |
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.