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 |
||
| 5 | class SubsetContainer extends \SplHeap |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var BasePartitionAlgorithm |
||
| 10 | */ |
||
| 11 | protected $algo; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Override compare method. |
||
| 15 | * |
||
| 16 | * @param Subset $a |
||
| 17 | * @param Subset $b |
||
| 18 | * |
||
| 19 | * @return int |
||
| 20 | */ |
||
| 21 | public function compare($a, $b) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param $partition |
||
| 34 | */ |
||
| 35 | public function setPartition($partition) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param SubsetItem[] $items |
||
| 46 | */ |
||
| 47 | public function addItemsToSubset(array $items = array()) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param \drupol\phpartition\SubsetItem $item |
||
| 56 | */ |
||
| 57 | public function addItemToSubset(SubsetItem $item) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return Subset[] |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function getSubsets() |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function getSubsetsAndItemsAsArray() |
|
| 93 | |||
| 94 | /** |
||
| 95 | * @param \drupol\phpartition\BasePartitionAlgorithm $algo |
||
| 96 | */ |
||
| 97 | public function setAlgo(BasePartitionAlgorithm $algo) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @return BasePartitionAlgorithm |
||
| 104 | */ |
||
| 105 | public function getAlgo() |
||
| 109 | } |
||
| 110 |
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.