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\Exception; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Optimizely variation reach. |
13
|
|
|
*/ |
14
|
|
|
class VariationReach |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Total number of visitors exposed to this particular variation |
18
|
|
|
* @var integer |
19
|
|
|
*/ |
20
|
|
|
private $count; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The name of the variation |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $name; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The unique identifier for the variation |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $variationId; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @var number |
37
|
|
|
*/ |
38
|
|
|
private $variationReach; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Constructor. |
42
|
|
|
*/ |
43
|
3 |
|
public function __construct($options = array()) |
44
|
|
|
{ |
45
|
3 |
|
foreach ($options as $name=>$value) { |
46
|
|
|
switch ($name) { |
47
|
3 |
|
case 'count': $this->setCount($value); break; |
|
|
|
|
48
|
3 |
|
case 'name': $this->setName($value); break; |
|
|
|
|
49
|
3 |
|
case 'variation_id': $this->setVariationId($value); break; |
|
|
|
|
50
|
3 |
|
case 'variation_reach': $this->setVariationReach($value); break; |
|
|
|
|
51
|
|
|
default: |
52
|
3 |
|
throw new Exception('Unknown option found in VariationReach entity: ' . $name); |
53
|
|
|
} |
54
|
|
|
} |
55
|
3 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Returns this object as array. |
59
|
|
|
*/ |
60
|
1 |
|
public function toArray() |
61
|
|
|
{ |
62
|
|
|
$options = array( |
63
|
1 |
|
'count' => $this->getCount(), |
64
|
1 |
|
'name' => $this->getName(), |
65
|
1 |
|
'variation_id' => $this->getVariationId(), |
66
|
1 |
|
'variation_reach' => $this->getVariationReach(), |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
// Remove options with empty values |
70
|
1 |
|
$cleanedOptions = array(); |
71
|
1 |
|
foreach ($options as $name=>$value) { |
72
|
1 |
|
if ($value!==null) |
73
|
1 |
|
$cleanedOptions[$name] = $value; |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
return $cleanedOptions; |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function getCount() |
80
|
|
|
{ |
81
|
1 |
|
return $this->count; |
82
|
|
|
} |
83
|
|
|
|
84
|
3 |
|
public function setCount($count) |
85
|
|
|
{ |
86
|
3 |
|
$this->count = $count; |
87
|
3 |
|
} |
88
|
|
|
|
89
|
1 |
|
public function getName() |
90
|
|
|
{ |
91
|
1 |
|
return $this->name; |
92
|
|
|
} |
93
|
|
|
|
94
|
3 |
|
public function setName($name) |
95
|
|
|
{ |
96
|
3 |
|
$this->name = $name; |
97
|
3 |
|
} |
98
|
|
|
|
99
|
1 |
|
public function getVariationId() |
100
|
|
|
{ |
101
|
1 |
|
return $this->variationId; |
102
|
|
|
} |
103
|
|
|
|
104
|
3 |
|
public function setVariationId($variationId) |
105
|
|
|
{ |
106
|
3 |
|
$this->variationId = $variationId; |
107
|
3 |
|
} |
108
|
|
|
|
109
|
1 |
|
public function getVariationReach() |
110
|
|
|
{ |
111
|
1 |
|
return $this->variationReach; |
112
|
|
|
} |
113
|
|
|
|
114
|
3 |
|
public function setVariationReach($variationReach) |
115
|
|
|
{ |
116
|
3 |
|
$this->variationReach = $variationReach; |
117
|
3 |
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
|
122
|
|
|
|
123
|
|
|
|
124
|
|
|
|
125
|
|
|
|
126
|
|
|
|
127
|
|
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
|
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.