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 |
||
16 | class ExperimentResults |
||
17 | { |
||
18 | /** |
||
19 | * The significance level at which you would like to declare winning and |
||
20 | * losing variations. A lower number minimizes the time needed to declare |
||
21 | * a winning or losing variation, but increases the risk that your results |
||
22 | * aren't true winners and losers. |
||
23 | * @var number |
||
24 | */ |
||
25 | private $confidenceThreshold; |
||
26 | |||
27 | /** |
||
28 | * The latest time to count events in results |
||
29 | * @var string |
||
30 | */ |
||
31 | private $endTime; |
||
32 | |||
33 | /** |
||
34 | * The unique identifier for the Experiment. |
||
35 | * @var type |
||
36 | */ |
||
37 | private $experimentId; |
||
38 | |||
39 | /** |
||
40 | * The breakdown of experiment results by metric |
||
41 | * @var array[ExperimentMetricResult] |
||
42 | */ |
||
43 | private $metrics; |
||
44 | |||
45 | /** |
||
46 | * The total number of users exposed to a different experience |
||
47 | * @var ExperimentVariationReach |
||
48 | */ |
||
49 | private $reach; |
||
50 | |||
51 | /** |
||
52 | * The earliest time to count events in results |
||
53 | * @var string |
||
54 | */ |
||
55 | private $startTime; |
||
56 | |||
57 | /** |
||
58 | * Constructor. |
||
59 | */ |
||
60 | 3 | View Code Duplication | public function __construct($options = array()) |
82 | |||
83 | /** |
||
84 | * Returns this object as array. |
||
85 | */ |
||
86 | 1 | public function toArray() |
|
110 | |||
111 | 3 | public function getConfidenceThreshold() |
|
115 | |||
116 | 3 | public function setConfidenceThreshold($confidenceThreshold) |
|
120 | |||
121 | 1 | public function getEndTime() |
|
125 | |||
126 | 3 | public function setEndTime($endTime) |
|
130 | |||
131 | 1 | public function getExperimentId() |
|
135 | |||
136 | 3 | public function setExperimentId($experimentId) |
|
140 | |||
141 | 1 | public function getMetrics() |
|
145 | |||
146 | 3 | public function setMetrics($metrics) |
|
150 | |||
151 | 1 | public function getReach() |
|
155 | |||
156 | 3 | public function setReach($reach) |
|
160 | |||
161 | 2 | public function getStartTime() |
|
165 | |||
166 | 3 | public function setStartTime($startTime) |
|
170 | } |
||
171 | |||
181 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.