1 | <?php |
||
12 | class VariationReach |
||
13 | { |
||
14 | /** |
||
15 | * Total number of visitors exposed to this particular variation |
||
16 | * @var integer |
||
17 | */ |
||
18 | private $count; |
||
19 | |||
20 | /** |
||
21 | * The name of the variation |
||
22 | * @var string |
||
23 | */ |
||
24 | private $name; |
||
25 | |||
26 | /** |
||
27 | * The unique identifier for the variation |
||
28 | * @var string |
||
29 | */ |
||
30 | private $variationId; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * @var number |
||
35 | */ |
||
36 | private $variationReach; |
||
37 | |||
38 | /** |
||
39 | * Constructor. |
||
40 | */ |
||
41 | 3 | public function __construct($options = array()) |
|
42 | { |
||
43 | 3 | foreach ($options as $name=>$value) { |
|
44 | switch ($name) { |
||
45 | 3 | case 'count': $this->setCount($value); break; |
|
46 | 3 | case 'name': $this->setName($value); break; |
|
47 | 3 | case 'variation_id': $this->setVariationId($value); break; |
|
48 | 3 | case 'variation_reach': $this->setVariationReach($value); break; |
|
49 | default: |
||
50 | 3 | throw new \Exception('Unknown option: ' . $name); |
|
51 | } |
||
52 | } |
||
53 | 3 | } |
|
54 | |||
55 | /** |
||
56 | * Returns this object as array. |
||
57 | */ |
||
58 | 1 | public function toArray() |
|
59 | { |
||
60 | $options = array( |
||
61 | 1 | 'count' => $this->getCount(), |
|
62 | 1 | 'name' => $this->getName(), |
|
63 | 1 | 'variation_id' => $this->getVariationId(), |
|
64 | 1 | 'variation_reach' => $this->getVariationReach(), |
|
65 | ); |
||
66 | |||
67 | // Remove options with empty values |
||
68 | 1 | $cleanedOptions = array(); |
|
69 | 1 | foreach ($options as $name=>$value) { |
|
70 | 1 | if ($value!==null) |
|
71 | 1 | $cleanedOptions[$name] = $value; |
|
72 | } |
||
73 | |||
74 | 1 | return $cleanedOptions; |
|
75 | } |
||
76 | |||
77 | 1 | public function getCount() |
|
81 | |||
82 | 3 | public function setCount($count) |
|
86 | |||
87 | 1 | public function getName() |
|
91 | |||
92 | 3 | public function setName($name) |
|
96 | |||
97 | 1 | public function getVariationId() |
|
101 | |||
102 | 3 | public function setVariationId($variationId) |
|
106 | |||
107 | 1 | public function getVariationReach() |
|
111 | |||
112 | 3 | public function setVariationReach($variationReach) |
|
116 | } |
||
117 | |||
118 | |||
128 |
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.