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 = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Product constructor. |
||
| 30 | * |
||
| 31 | * @param array $datasetArray |
||
| 32 | * The array of dataset. |
||
| 33 | */ |
||
| 34 | public function __construct(array $datasetArray) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | public function current() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * {@inheritdoc} |
||
| 61 | */ |
||
| 62 | public function next() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * {@inheritdoc} |
||
| 83 | */ |
||
| 84 | public function key() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * {@inheritdoc} |
||
| 91 | */ |
||
| 92 | public function valid() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * {@inheritdoc} |
||
| 107 | */ |
||
| 108 | public function rewind() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * {@inheritdoc} |
||
| 119 | */ |
||
| 120 | public function count() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Convert the iterator into an array. |
||
| 133 | * |
||
| 134 | * @return array |
||
| 135 | * The elements. |
||
| 136 | */ |
||
| 137 | View Code Duplication | public function toArray() |
|
| 147 | } |
||
| 148 |
This check marks variable names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.