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 | /** |
||
16 | * The key. |
||
17 | * |
||
18 | * @var int |
||
19 | */ |
||
20 | protected $key; |
||
21 | |||
22 | /** |
||
23 | * The iterators. |
||
24 | * |
||
25 | * @var \Iterator[] |
||
26 | */ |
||
27 | protected $iterators = array(); |
||
28 | |||
29 | /** |
||
30 | * Product constructor. |
||
31 | * |
||
32 | * @param array $datasetArray |
||
33 | * The array of dataset. |
||
34 | */ |
||
35 | 4 | public function __construct(array $datasetArray) |
|
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | 4 | public function current() |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 4 | public function next() |
|
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | public function key() |
||
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | 4 | public function valid() |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | 4 | public function rewind() |
|
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | 4 | public function count() |
|
130 | |||
131 | /** |
||
132 | * Convert the iterator into an array. |
||
133 | * |
||
134 | * @return array |
||
135 | * The elements. |
||
136 | */ |
||
137 | 4 | 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
.