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 |
||
15 | class ExperimentVariationReach |
||
16 | { |
||
17 | /** |
||
18 | * Baseline count |
||
19 | * @var integer |
||
20 | */ |
||
21 | private $baselineCount; |
||
22 | |||
23 | /** |
||
24 | * Baseline reach |
||
25 | * @var number |
||
26 | */ |
||
27 | private $baselineReach; |
||
28 | |||
29 | /** |
||
30 | * Total number of visitors exposed to the experiment |
||
31 | * @var integer |
||
32 | */ |
||
33 | private $totalCount; |
||
34 | |||
35 | /** |
||
36 | * Treatment count |
||
37 | * @var number |
||
38 | */ |
||
39 | private $treatmentCount; |
||
40 | |||
41 | /** |
||
42 | * Treatment reach |
||
43 | * @var number |
||
44 | */ |
||
45 | private $treatmentReach; |
||
46 | |||
47 | /** |
||
48 | * A map of reach for each Variation keyed by Variation ID |
||
49 | * @var array[VariationReach] |
||
50 | */ |
||
51 | private $variations; |
||
52 | |||
53 | /** |
||
54 | * Constructor. |
||
55 | */ |
||
56 | 3 | public function __construct($options = array()) |
|
78 | |||
79 | /** |
||
80 | * Returns this object as array. |
||
81 | */ |
||
82 | 1 | public function toArray() |
|
106 | |||
107 | 1 | public function getBaselineCount() |
|
111 | |||
112 | 3 | public function setBaselineCount($baselineCount) |
|
116 | |||
117 | 1 | public function getBaselineReach() |
|
121 | |||
122 | 3 | public function setBaselineReach($baselineReach) |
|
126 | |||
127 | 1 | public function getTotalCount() |
|
131 | |||
132 | 3 | public function setTotalCount($totalCount) |
|
136 | |||
137 | 1 | public function getTreatmentCount() |
|
141 | |||
142 | 3 | public function setTreatmentCount($treatmentCount) |
|
146 | |||
147 | 1 | public function getTreatmentReach() |
|
151 | |||
152 | 3 | public function setTreatmentReach($treatmentReach) |
|
156 | |||
157 | 1 | public function getVariations() |
|
161 | |||
162 | 3 | public function setVariations($variations) |
|
166 | } |
||
167 | |||
178 |
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.