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 |
||
17 | class ExperimentResults |
||
18 | { |
||
19 | /** |
||
20 | * The significance level at which you would like to declare winning and |
||
21 | * losing variations. A lower number minimizes the time needed to declare |
||
22 | * a winning or losing variation, but increases the risk that your results |
||
23 | * aren't true winners and losers. |
||
24 | * @var number |
||
25 | */ |
||
26 | private $confidenceThreshold; |
||
27 | |||
28 | /** |
||
29 | * The latest time to count events in results |
||
30 | * @var string |
||
31 | */ |
||
32 | private $endTime; |
||
33 | |||
34 | /** |
||
35 | * The unique identifier for the Experiment. |
||
36 | * @var type |
||
37 | */ |
||
38 | private $experimentId; |
||
39 | |||
40 | /** |
||
41 | * The breakdown of experiment results by metric |
||
42 | * @var array[ExperimentMetricResult] |
||
43 | */ |
||
44 | private $metrics; |
||
45 | |||
46 | /** |
||
47 | * The total number of users exposed to a different experience |
||
48 | * @var ExperimentVariationReach |
||
49 | */ |
||
50 | private $reach; |
||
51 | |||
52 | /** |
||
53 | * The earliest time to count events in results |
||
54 | * @var string |
||
55 | */ |
||
56 | private $startTime; |
||
57 | |||
58 | /** |
||
59 | * |
||
60 | * @var StatsConfig |
||
61 | */ |
||
62 | private $statsConfig; |
||
63 | |||
64 | /** |
||
65 | * Constructor. |
||
66 | */ |
||
67 | 3 | public function __construct($options = array()) |
|
90 | |||
91 | /** |
||
92 | * Returns this object as array. |
||
93 | */ |
||
94 | public function toArray() |
||
119 | |||
120 | public function getConfidenceThreshold() |
||
124 | |||
125 | 3 | public function setConfidenceThreshold($confidenceThreshold) |
|
129 | |||
130 | public function getEndTime() |
||
134 | |||
135 | 3 | public function setEndTime($endTime) |
|
139 | |||
140 | public function getExperimentId() |
||
144 | |||
145 | 3 | public function setExperimentId($experimentId) |
|
149 | |||
150 | public function getMetrics() |
||
154 | |||
155 | public function setMetrics($metrics) |
||
159 | |||
160 | public function getReach() |
||
164 | |||
165 | public function setReach($reach) |
||
169 | |||
170 | public function getStartTime() |
||
174 | |||
175 | public function setStartTime($startTime) |
||
179 | |||
180 | public function getStatsConfig() |
||
184 | |||
185 | public function setStatsConfig($statsConfig) |
||
189 | } |
||
190 | |||
200 |
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.