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 Experiments |
||
17 | { |
||
18 | /** |
||
19 | * Optimizely API Client. |
||
20 | * @var WebMarketingROI\OptimizelyPHP\OptimizelyApiClient |
||
21 | */ |
||
22 | private $client; |
||
23 | |||
24 | /** |
||
25 | * Constructor. |
||
26 | */ |
||
27 | 12 | public function __construct($client) |
|
31 | |||
32 | /** |
||
33 | * Get a list of all the experiments by Project or Campaign |
||
34 | * @param integer $projectId |
||
35 | * @param integer $campaignId |
||
36 | * @param boolean $includeClassic |
||
37 | * @param integer $page |
||
38 | * @param integer $perPage |
||
39 | * @return Result |
||
40 | * @throws Exception |
||
41 | */ |
||
42 | 4 | public function listAll($projectId, $campaignId=null, $includeClassic=false, $page=1, $perPage=25) |
|
74 | |||
75 | /** |
||
76 | * Get metadata for a single Experiment. |
||
77 | * @param integer $experimentId |
||
78 | * @return Result |
||
79 | * @throws Exception |
||
80 | */ |
||
81 | 3 | View Code Duplication | public function get($experimentId) |
99 | |||
100 | /** |
||
101 | * Get results for a single experiment |
||
102 | * @param integer $experimentId The id for the experiment you want results for |
||
103 | * @param integer $baselineVariationId The id of the variation to use as the baseline to compare against other variations. Defaults to the first variation if not provided. |
||
104 | * @param string $startTime The earliest time to count events in results. Defaults to the time that the experiment was first activated. |
||
105 | * @param string $endTime The latest time to count events in results. Defaults to the time the experiment was last active or the current time if the experiment is still running. |
||
106 | * @return Result |
||
107 | * @throws Exception |
||
108 | */ |
||
109 | 1 | public function getResults($experimentId, $baselineVariationId = null, $startTime = null, $endTime = null) |
|
128 | |||
129 | /** |
||
130 | * Create an experiment in a Project. |
||
131 | * @param Experiment $experiment |
||
132 | * @param boolean $publish Set to true to make the the experiment live to the world upon creation. |
||
133 | * @return Result |
||
134 | * @throw Exception |
||
135 | */ |
||
136 | 1 | public function create($experiment, $publish) |
|
162 | |||
163 | /** |
||
164 | * Update an Experiment by ID |
||
165 | * @param integer $experimentId |
||
166 | * @param Experiment $experiment |
||
167 | * @param boolean $overrideChanges If there are draft changes already in the experiment, you can override those changes by providing this query parameter. |
||
168 | * @param boolean $publish Whether to publish the changes to the world. |
||
169 | * @return Result |
||
170 | * @throws Exception |
||
171 | */ |
||
172 | 1 | public function update($experimentId, $experiment, $overrideChanges, $publish) |
|
201 | |||
202 | /** |
||
203 | * Delete Experiment by ID |
||
204 | * @param integer $experimentId |
||
205 | * @return Result |
||
206 | * @throws Exception |
||
207 | */ |
||
208 | 1 | public function delete($experimentId) |
|
215 | } |
||
216 | |||
217 |