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 |
||
19 | class TreeMap |
||
20 | { |
||
21 | /** |
||
22 | * @var TreeMap The tree map |
||
23 | * |
||
24 | * @since 1.0.5 |
||
25 | */ |
||
26 | protected $tree; |
||
27 | |||
28 | /** |
||
29 | * @var SortedMap The sorted map |
||
30 | * |
||
31 | * @since 1.0.5 |
||
32 | */ |
||
33 | protected $data; |
||
34 | |||
35 | /** |
||
36 | * Provider for counts |
||
37 | * |
||
38 | * @return iterator Iterator on count |
||
39 | * |
||
40 | * @since 1.0.5 |
||
41 | */ |
||
42 | public function provideCounts() |
||
49 | |||
50 | /** |
||
51 | * Provider for counts |
||
52 | * |
||
53 | * @return iterator Iterator on type |
||
54 | * |
||
55 | * @since 1.0.5 |
||
56 | */ |
||
57 | public function provideTypes() |
||
64 | |||
65 | /** |
||
66 | * Create the tree map. |
||
67 | * |
||
68 | * @param array $params Array of parameters |
||
69 | * |
||
70 | * @return void |
||
71 | * |
||
72 | * @since 1.0.5 |
||
73 | */ |
||
74 | public function init($params) |
||
78 | |||
79 | /** |
||
80 | * Create the sorted map. |
||
81 | * |
||
82 | * @param array $params Array of parameters |
||
83 | * |
||
84 | * @return void |
||
85 | * |
||
86 | * @since 1.0.5 |
||
87 | */ |
||
88 | public function data($params) |
||
125 | |||
126 | /** |
||
127 | * Clear the tree map. |
||
128 | * |
||
129 | * @param array $params Array of parameters |
||
130 | * |
||
131 | * @return void |
||
132 | * |
||
133 | * @since 1.0.5 |
||
134 | */ |
||
135 | public function finish($params) |
||
139 | |||
140 | /** |
||
141 | * @BeforeMethods({"init", "data"}) |
||
142 | * @AfterMethods({"finish"}) |
||
143 | * @Revs(5) |
||
144 | * @ParamProviders({"provideCounts"}) |
||
145 | * |
||
146 | * @param array $params Array of parameters |
||
147 | * |
||
148 | * @return void |
||
149 | * |
||
150 | * @since 1.0.5 |
||
151 | */ |
||
152 | View Code Duplication | public function benchFill($params) |
|
159 | |||
160 | /** |
||
161 | * @BeforeMethods({"init", "benchFill", "data"}) |
||
162 | * @AfterMethods({"finish"}) |
||
163 | * @Revs(5) |
||
164 | * @ParamProviders({"provideCounts", "provideTypes"}) |
||
165 | * |
||
166 | * @param array $params Array of parameters |
||
167 | * |
||
168 | * @return void |
||
169 | * |
||
170 | * @since 1.0.5 |
||
171 | */ |
||
172 | public function benchSearch($params) |
||
197 | |||
198 | /** |
||
199 | * @BeforeMethods({"init", "benchFill", "data"}) |
||
200 | * @AfterMethods({"finish"}) |
||
201 | * @Revs(5) |
||
202 | * @ParamProviders({"provideCounts"}) |
||
203 | * |
||
204 | * @param array $params Array of parameters |
||
205 | * |
||
206 | * @return void |
||
207 | * |
||
208 | * @since 1.0.5 |
||
209 | */ |
||
210 | View Code Duplication | public function benchClean($params) |
|
217 | } |
||
218 | |||
219 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.