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 Product extends Combinatorics implements \Iterator, \Countable { |
||
13 | |||
14 | /** |
||
15 | * The key. |
||
16 | * |
||
17 | * @var int |
||
18 | */ |
||
19 | protected $key; |
||
20 | |||
21 | /** |
||
22 | * The iterators. |
||
23 | * |
||
24 | * @var \Iterator[] |
||
25 | */ |
||
26 | protected $iterators = array(); |
||
27 | |||
28 | /** |
||
29 | * Product constructor. |
||
30 | * |
||
31 | * @param array $datasetArray |
||
32 | * The array of dataset. |
||
33 | */ |
||
34 | 4 | public function __construct(array $datasetArray) { |
|
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 4 | public function current() { |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 4 | public function next() { |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public function key() { |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | 4 | public function valid() { |
|
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | 4 | public function rewind() { |
|
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | 4 | public function count() { |
|
123 | |||
124 | /** |
||
125 | * Convert the iterator into an array. |
||
126 | * |
||
127 | * @return array |
||
128 | * The elements. |
||
129 | */ |
||
130 | 4 | View Code Duplication | public function toArray() { |
139 | |||
140 | } |
||
141 |