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 |
||
| 10 | class Product extends Combinatorics implements \Iterator { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var int |
||
| 14 | */ |
||
| 15 | protected $key; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var \Iterator[] |
||
| 19 | */ |
||
| 20 | protected $iterators = array(); |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Product constructor. |
||
| 24 | * |
||
| 25 | * @param array $datasetArray |
||
| 26 | * @param int|null $length |
||
| 27 | */ |
||
| 28 | 2 | public function __construct(array $datasetArray, $length = NULL) { |
|
| 37 | |||
| 38 | /** |
||
| 39 | * @inheritdoc |
||
| 40 | */ |
||
| 41 | 2 | public function current() { |
|
| 50 | |||
| 51 | /** |
||
| 52 | * @inheritdoc |
||
| 53 | */ |
||
| 54 | 2 | public function next() { |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @inheritdoc |
||
| 75 | */ |
||
| 76 | public function key() { |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @inheritdoc |
||
| 82 | */ |
||
| 83 | 2 | public function valid() { |
|
| 94 | |||
| 95 | /** |
||
| 96 | * @inheritdoc |
||
| 97 | */ |
||
| 98 | 2 | public function rewind() { |
|
| 105 | |||
| 106 | /** |
||
| 107 | * @return int |
||
| 108 | */ |
||
| 109 | 2 | public function count() { |
|
| 118 | |||
| 119 | /** |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | 2 | View Code Duplication | public function toArray() { |
| 131 | |||
| 132 | } |
||
| 133 |