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 namespace BuildR\Collection; |
||
19 | class Set implements CollectionInterface { |
||
20 | |||
21 | protected $data = []; |
||
22 | |||
23 | private $position = 0; |
||
24 | |||
25 | /** |
||
26 | * Set constructor. |
||
27 | * |
||
28 | * @param null|array $values |
||
29 | */ |
||
30 | 23 | public function __construct($values = NULL) { |
|
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 8 | public function toArray() { |
|
40 | 8 | return $this->data; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 23 | public function add($element) { |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 17 | public function addAll($elements) { |
|
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 1 | public function clear() { |
|
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | 9 | public function contains($element) { |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 8 | View Code Duplication | public function containsAll($elements) { |
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | 5 | public function containsAny($elements) { |
|
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | 5 | public function equals(CollectionInterface $collection) { |
|
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | 1 | public function isEmpty() { |
|
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | 2 | public function remove($element) { |
|
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | 1 | View Code Duplication | public function removeAll($elements) { |
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | 1 | public function retainAll($elements) { |
|
183 | |||
184 | /** |
||
185 | * {@inheritdoc} |
||
186 | */ |
||
187 | 12 | public function size() { |
|
190 | |||
191 | /** |
||
192 | * {@inheritdoc} |
||
193 | * |
||
194 | * @codeCoverageIgnore |
||
195 | */ |
||
196 | public function current() { |
||
199 | |||
200 | /** |
||
201 | * {@inheritdoc} |
||
202 | * |
||
203 | * @codeCoverageIgnore |
||
204 | */ |
||
205 | public function next() { |
||
208 | |||
209 | /** |
||
210 | * {@inheritdoc} |
||
211 | * |
||
212 | * @codeCoverageIgnore |
||
213 | */ |
||
214 | public function key() { |
||
217 | |||
218 | /** |
||
219 | * {@inheritdoc} |
||
220 | * |
||
221 | * @codeCoverageIgnore |
||
222 | */ |
||
223 | public function valid() { |
||
226 | |||
227 | /** |
||
228 | * {@inheritdoc} |
||
229 | * |
||
230 | * @codeCoverageIgnore |
||
231 | */ |
||
232 | public function rewind() { |
||
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | 7 | public function count() { |
|
242 | |||
243 | /** |
||
244 | * @param array|\BuildR\Collection\Interfaces\CollectionInterface $elements |
||
245 | * |
||
246 | * @return array |
||
247 | */ |
||
248 | 17 | protected function checkAndConvertInputCollection($elements) { |
|
255 | |||
256 | } |
||
257 |