1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
4
|
|
|
* @date 12 October 2016 |
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
6
|
|
|
*/ |
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Resource\v2; |
8
|
|
|
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\VariationReach; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Optimizely experiment variation reach. |
13
|
|
|
*/ |
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()) |
56
|
|
|
{ |
57
|
3 |
|
foreach ($options as $name=>$value) { |
58
|
|
|
switch ($name) { |
59
|
3 |
|
case 'baseline_count': $this->setBaselineCount($value); break; |
|
|
|
|
60
|
3 |
|
case 'baseline_reach': $this->setBaselineReach($value); break; |
|
|
|
|
61
|
3 |
|
case 'total_count': $this->setTotalCount($value); break; |
|
|
|
|
62
|
3 |
|
case 'treatment_count': $this->setTreatmentCount($value); break; |
|
|
|
|
63
|
3 |
|
case 'treatment_reach': $this->setTreatmentReach($value); break; |
|
|
|
|
64
|
3 |
View Code Duplication |
case 'variations': { |
|
|
|
|
65
|
3 |
|
$variations = array(); |
66
|
3 |
|
foreach ($value as $name=>$variationInfo) { |
67
|
3 |
|
$variations[$name] = new VariationReach($variationInfo); |
68
|
3 |
|
} |
69
|
3 |
|
$this->setVariations($variations); |
70
|
3 |
|
break; |
71
|
|
|
} |
72
|
|
|
default: |
73
|
|
|
throw new \Exception('Unknown option: ' . $name); |
74
|
|
|
} |
75
|
3 |
|
} |
76
|
3 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns this object as array. |
80
|
|
|
*/ |
81
|
1 |
|
public function toArray() |
82
|
|
|
{ |
83
|
|
|
$options = array( |
84
|
1 |
|
'baseline_count' => $this->getBaselineCount(), |
85
|
1 |
|
'baseline_reach' => $this->getBaselineReach(), |
86
|
1 |
|
'total_count' => $this->getTotalCount(), |
87
|
1 |
|
'treatment_count' => $this->getTreatmentCount(), |
88
|
1 |
|
'treatment_reach' => $this->getTreatmentReach(), |
89
|
1 |
|
'variations' => array(), |
90
|
1 |
|
); |
91
|
|
|
|
92
|
1 |
|
foreach ($this->getVariations() as $name=>$variation) { |
93
|
1 |
|
$options['variations'][$name] = $variation->toArray(); |
94
|
1 |
|
} |
95
|
|
|
|
96
|
|
|
// Remove options with empty values |
97
|
1 |
|
$cleanedOptions = array(); |
98
|
1 |
|
foreach ($options as $name=>$value) { |
99
|
1 |
|
if ($value!==null) |
100
|
1 |
|
$cleanedOptions[$name] = $value; |
101
|
1 |
|
} |
102
|
|
|
|
103
|
1 |
|
return $cleanedOptions; |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function getBaselineCount() |
107
|
|
|
{ |
108
|
1 |
|
return $this->baselineCount; |
109
|
|
|
} |
110
|
|
|
|
111
|
3 |
|
public function setBaselineCount($baselineCount) |
112
|
|
|
{ |
113
|
3 |
|
$this->baselineCount = $baselineCount; |
114
|
3 |
|
} |
115
|
|
|
|
116
|
1 |
|
public function getBaselineReach() |
117
|
|
|
{ |
118
|
1 |
|
return $this->baselineReach; |
119
|
|
|
} |
120
|
|
|
|
121
|
3 |
|
public function setBaselineReach($baselineReach) |
122
|
|
|
{ |
123
|
3 |
|
$this->baselineReach = $baselineReach; |
124
|
3 |
|
} |
125
|
|
|
|
126
|
1 |
|
public function getTotalCount() |
127
|
|
|
{ |
128
|
1 |
|
return $this->totalCount; |
129
|
|
|
} |
130
|
|
|
|
131
|
3 |
|
public function setTotalCount($totalCount) |
132
|
|
|
{ |
133
|
3 |
|
$this->totalCount = $totalCount; |
134
|
3 |
|
} |
135
|
|
|
|
136
|
1 |
|
public function getTreatmentCount() |
137
|
|
|
{ |
138
|
1 |
|
return $this->treatmentCount; |
139
|
|
|
} |
140
|
|
|
|
141
|
3 |
|
public function setTreatmentCount($treatmentCount) |
142
|
|
|
{ |
143
|
3 |
|
$this->treatmentCount = $treatmentCount; |
144
|
3 |
|
} |
145
|
|
|
|
146
|
1 |
|
public function getTreatmentReach() |
147
|
|
|
{ |
148
|
1 |
|
return $this->treatmentReach; |
149
|
|
|
} |
150
|
|
|
|
151
|
3 |
|
public function setTreatmentReach($treatmentReach) |
152
|
|
|
{ |
153
|
3 |
|
$this->treatmentReach = $treatmentReach; |
154
|
3 |
|
} |
155
|
|
|
|
156
|
1 |
|
public function getVariations() |
157
|
|
|
{ |
158
|
1 |
|
return $this->variations; |
159
|
|
|
} |
160
|
|
|
|
161
|
3 |
|
public function setVariations($variations) |
162
|
|
|
{ |
163
|
3 |
|
$this->variations = $variations; |
164
|
3 |
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
|
169
|
|
|
|
170
|
|
|
|
171
|
|
|
|
172
|
|
|
|
173
|
|
|
|
174
|
|
|
|
175
|
|
|
|
176
|
|
|
|
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.