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 { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var int |
||
| 16 | */ |
||
| 17 | protected $key; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var \Iterator[] |
||
| 21 | */ |
||
| 22 | protected $iterators = array(); |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Product constructor. |
||
| 26 | * |
||
| 27 | * @param array $datasetArray |
||
| 28 | * @param int|null $length |
||
| 29 | */ |
||
| 30 | 2 | public function __construct(array $datasetArray, $length = NULL) { |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @inheritdoc |
||
| 42 | */ |
||
| 43 | 2 | public function current() { |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @inheritdoc |
||
| 55 | */ |
||
| 56 | 2 | public function next() { |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @inheritdoc |
||
| 77 | */ |
||
| 78 | public function key() { |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @inheritdoc |
||
| 84 | */ |
||
| 85 | 2 | public function valid() { |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @inheritdoc |
||
| 99 | */ |
||
| 100 | 2 | public function rewind() { |
|
| 107 | |||
| 108 | /** |
||
| 109 | * @return int |
||
| 110 | */ |
||
| 111 | 2 | public function count() { |
|
| 120 | |||
| 121 | /** |
||
| 122 | * @return array |
||
| 123 | */ |
||
| 124 | 2 | View Code Duplication | public function toArray() { |
| 133 | |||
| 134 | } |
||
| 135 |