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 |
||
12 | class StoryPointManager |
||
13 | { |
||
14 | /** |
||
15 | * @var ActionManager |
||
16 | */ |
||
17 | private $actionManager; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | private $pattern = '/\(([0-9]*.?[0-9]*)\)/'; |
||
23 | |||
24 | /** |
||
25 | * @var \Trello\Client |
||
26 | */ |
||
27 | private $client; |
||
28 | |||
29 | /** |
||
30 | * StoryPointsManager constructor. |
||
31 | * |
||
32 | * @param TrelloClient $trelloClient |
||
33 | * @param ActionManager $actionManager |
||
34 | * @param string $pattern |
||
35 | */ |
||
36 | 25 | public function __construct(TrelloClient $trelloClient, ActionManager $actionManager, String $pattern = null) |
|
45 | |||
46 | /** |
||
47 | * @param string $pattern |
||
48 | */ |
||
49 | 1 | public function setPattern(String $pattern) |
|
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | 1 | public function getPattern() |
|
61 | |||
62 | /** |
||
63 | * @param $name |
||
64 | * |
||
65 | * @return int |
||
|
|||
66 | */ |
||
67 | 13 | public function parseStoryPoints($name) |
|
73 | |||
74 | /** |
||
75 | * @param Cardlist $list |
||
76 | * |
||
77 | * @return int |
||
78 | */ |
||
79 | 4 | public function countListStoryPoints(Cardlist $list) |
|
92 | |||
93 | /** |
||
94 | * Return an array of done story points per day. |
||
95 | * |
||
96 | * @param array $todoLists |
||
97 | * @param array $wipLists |
||
98 | * @param array $doneLists |
||
99 | * @param Sprint $sprint |
||
100 | * |
||
101 | * @return array|null |
||
102 | */ |
||
103 | 4 | public function getDoneStoryPoints(array $todoLists, array $wipLists, array $doneLists, Sprint $sprint) |
|
139 | |||
140 | /** |
||
141 | * @param array $todoLists |
||
142 | * @param array $wipLists |
||
143 | * @param array $doneLists |
||
144 | * @param Sprint $sprint |
||
145 | * |
||
146 | * @return int |
||
147 | */ |
||
148 | 3 | public function getTotalSprintStoryPoints(array $todoLists, array $wipLists, array $doneLists, Sprint $sprint) |
|
167 | |||
168 | /** |
||
169 | * @param $totalOfSprint |
||
170 | * @param Sprint $sprint |
||
171 | * |
||
172 | * @return float |
||
173 | */ |
||
174 | 2 | public function getAverageStoryPointsPerDay($totalOfSprint, Sprint $sprint) |
|
178 | } |
||
179 |
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.