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 |
||
20 | class ObjectIterator extends ArrayCollection |
||
21 | { |
||
22 | /** |
||
23 | * @var Converter |
||
24 | */ |
||
25 | private $converter; |
||
26 | |||
27 | /** |
||
28 | * @var array Aliases information. |
||
29 | */ |
||
30 | private $alias; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $rawObjects; |
||
36 | |||
37 | /** |
||
38 | * @var \Closure |
||
39 | */ |
||
40 | private $convertCallback; |
||
41 | |||
42 | /** |
||
43 | * Using part of abstract iterator functionality only. |
||
44 | * |
||
45 | * @param Converter $converter |
||
46 | * @param array $objects |
||
47 | * @param array $alias |
||
48 | */ |
||
49 | public function __construct($converter, $objects, $alias) |
||
70 | |||
71 | /** |
||
72 | * Converts all existing array values into their document equivalents. |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | public function toArray() |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | protected function convertDocument(array $document) |
||
99 | |||
100 | /** |
||
101 | * Converts a raw object when the key for the object must be determined first. |
||
102 | * |
||
103 | * @param array $rawObject |
||
104 | * |
||
105 | * @return bool|object |
||
106 | */ |
||
107 | protected function convertFromValue(array $rawObject) |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function getIterator() |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | View Code Duplication | public function first() |
|
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | View Code Duplication | public function last() |
|
154 | |||
155 | /** |
||
156 | * {@inheritdoc} |
||
157 | */ |
||
158 | View Code Duplication | public function next() |
|
169 | |||
170 | /** |
||
171 | * {@inheritdoc} |
||
172 | */ |
||
173 | View Code Duplication | public function current() |
|
184 | |||
185 | /** |
||
186 | * {@inheritdoc} |
||
187 | */ |
||
188 | View Code Duplication | public function get($offset) |
|
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | public function getValues() |
||
208 | |||
209 | /** |
||
210 | * {@inheritdoc} |
||
211 | */ |
||
212 | public function map(Closure $func) |
||
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | public function filter(Closure $p) |
||
224 | |||
225 | /** |
||
226 | * {@inheritdoc} |
||
227 | */ |
||
228 | protected function createFrom(array $elements) |
||
232 | } |
||
233 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.