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 |
||
| 11 | class Product extends Combinatorics implements IteratorInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * The key. |
||
| 15 | * |
||
| 16 | * @var int |
||
| 17 | */ |
||
| 18 | protected $key; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * The iterators. |
||
| 22 | * |
||
| 23 | * @var \Iterator[] |
||
| 24 | */ |
||
| 25 | protected $iterators = []; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Product constructor. |
||
| 29 | * |
||
| 30 | * @param array $datasetArray |
||
| 31 | * The array of dataset |
||
| 32 | */ |
||
| 33 | 4 | public function __construct(array $datasetArray) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritdoc} |
||
| 46 | */ |
||
| 47 | 4 | public function current() |
|
| 57 | |||
| 58 | /** |
||
| 59 | * {@inheritdoc} |
||
| 60 | */ |
||
| 61 | 4 | public function next() |
|
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | 4 | public function valid() |
|
| 95 | |||
| 96 | /** |
||
| 97 | * {@inheritdoc} |
||
| 98 | */ |
||
| 99 | 4 | public function rewind() |
|
| 107 | |||
| 108 | /** |
||
| 109 | * {@inheritdoc} |
||
| 110 | */ |
||
| 111 | 4 | public function count() |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Convert the iterator into an array. |
||
| 124 | * |
||
| 125 | * @return array |
||
| 126 | * The elements |
||
| 127 | */ |
||
| 128 | 4 | View Code Duplication | public function toArray() |
| 138 | } |
||
| 139 |
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.