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 |
||
| 14 | class ExperimentVariationReach |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Baseline count |
||
| 18 | * @var integer |
||
| 19 | */ |
||
| 20 | private $baselineCount; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Baseline reach |
||
| 24 | * @var number |
||
| 25 | */ |
||
| 26 | private $baselineReach; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Total number of visitors exposed to the experiment |
||
| 30 | * @var integer |
||
| 31 | */ |
||
| 32 | private $totalCount; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Treatment count |
||
| 36 | * @var number |
||
| 37 | */ |
||
| 38 | private $treatmentCount; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Treatment reach |
||
| 42 | * @var number |
||
| 43 | */ |
||
| 44 | private $treatmentReach; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * A map of reach for each Variation keyed by Variation ID |
||
| 48 | * @var array[VariationReach] |
||
| 49 | */ |
||
| 50 | private $variations; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Constructor. |
||
| 54 | */ |
||
| 55 | 3 | public function __construct($options = array()) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Returns this object as array. |
||
| 80 | */ |
||
| 81 | 1 | public function toArray() |
|
| 105 | |||
| 106 | 1 | public function getBaselineCount() |
|
| 110 | |||
| 111 | 3 | public function setBaselineCount($baselineCount) |
|
| 115 | |||
| 116 | 1 | public function getBaselineReach() |
|
| 120 | |||
| 121 | 3 | public function setBaselineReach($baselineReach) |
|
| 125 | |||
| 126 | 1 | public function getTotalCount() |
|
| 130 | |||
| 131 | 3 | public function setTotalCount($totalCount) |
|
| 135 | |||
| 136 | 1 | public function getTreatmentCount() |
|
| 140 | |||
| 141 | 3 | public function setTreatmentCount($treatmentCount) |
|
| 145 | |||
| 146 | 1 | public function getTreatmentReach() |
|
| 150 | |||
| 151 | 3 | public function setTreatmentReach($treatmentReach) |
|
| 155 | |||
| 156 | 1 | public function getVariations() |
|
| 160 | |||
| 161 | 3 | public function setVariations($variations) |
|
| 165 | } |
||
| 166 | |||
| 177 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.