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 Combinations extends Combinatorics implements \Iterator { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | protected $c = array(); |
||
|
|
|||
| 18 | |||
| 19 | /** |
||
| 20 | * @var int |
||
| 21 | */ |
||
| 22 | protected $count = 0; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var int |
||
| 26 | */ |
||
| 27 | protected $pos = 0; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Combinations constructor. |
||
| 31 | * |
||
| 32 | * @param array $dataset |
||
| 33 | * @param null $length |
||
| 34 | */ |
||
| 35 | 6 | public function __construct(array $dataset = array(), $length = NULL) { |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @return int |
||
| 42 | */ |
||
| 43 | public function key() { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | 6 | public function current() { |
|
| 57 | |||
| 58 | /** |
||
| 59 | * |
||
| 60 | */ |
||
| 61 | 6 | public function next() { |
|
| 69 | |||
| 70 | /** |
||
| 71 | * |
||
| 72 | */ |
||
| 73 | 6 | public function rewind() { |
|
| 77 | |||
| 78 | /** |
||
| 79 | * @return bool |
||
| 80 | */ |
||
| 81 | 6 | public function valid() { |
|
| 84 | |||
| 85 | /** |
||
| 86 | * @return bool |
||
| 87 | */ |
||
| 88 | 6 | protected function _next() { |
|
| 103 | |||
| 104 | /** |
||
| 105 | * @return array |
||
| 106 | */ |
||
| 107 | 6 | View Code Duplication | public function toArray() { |
| 116 | |||
| 117 | /** |
||
| 118 | * @return int |
||
| 119 | */ |
||
| 120 | 3 | public function count() { |
|
| 123 | |||
| 124 | } |
||
| 125 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.