| 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\VariantResults; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Optimizely campaign metric results. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class CampaignMetricResults | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private $eventName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * Conversions indicate the total number of visitors or sessions where the  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * event happened. Impressions indicate the total number of times the event  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * happened (possibly multiple per visitor or session). Revenue indicates  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * the sum of all revenue sent from all events in the Campaign.  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Can be 'conversions', 'impressions' or 'revenue'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     private $measure; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     private $metricId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @var integer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     private $priority; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * A map of results for the variants affected by the campaign. Variants may  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * represent aggregated results scoped to the campaign and/or individual  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * experiment results scoped to just that experiment. The special variant  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * 'baseline' represents visitors that have been held back from any change  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * in experience across all Experiments in the Campaign. The special variant  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * 'campaign' represents the aggregated effect of all experiments included in  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * the Campaign. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @var VariantResults | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     private $results; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * Can be 'session', 'visitor' or 'event'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     private $unit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * Constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 3 |  |     public function __construct($options = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 3 |  |         foreach ($options as $name=>$value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             switch ($name) {                 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 3 |  |                 case 'event': $this->setEvent($value); break; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 3 |  |                 case 'event_name': $this->setEventName($value); break; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 3 |  |                 case 'measure': $this->setMeasure($value); break; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 3 |  |                 case 'metric_id': $this->setMetricId($value); break; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 3 |  |                 case 'priority': $this->setPriority($value); break; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 3 |  |                 case 'results': { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 3 |  |                     $results = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 3 |  |                     foreach ($value as $name=>$info) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 3 |  |                         $results[$name] = new VariantResults($info); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 3 |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 3 |  |                     $this->setResults($results);  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 3 |  |                     break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 3 |  |                 case 'unit': $this->setUnit($value); break; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                     throw new \Exception('Unknown option: ' . $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 3 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * Returns this object as array. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 1 |  |     public function toArray() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $options = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 1 |  |             'event' => $this->getEvent(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 1 |  |             'event_name' => $this->getEventName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 1 |  |             'measure' => $this->getMeasure(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 1 |  |             'metric_id' => $this->getMetricId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 | 1 |  |             'priority' => $this->getPriority(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 1 |  |             'results' => array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 1 |  |             'unit' => $this->getUnit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 1 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 1 |  |         foreach ($this->getResults() as $name=>$result) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 1 |  |             $options['results'][$name] = $result->toArray(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         // Remove options with empty values | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 1 |  |         $cleanedOptions = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 1 |  |         foreach ($options as $name=>$value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 1 |  |             if ($value!==null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 | 1 |  |                 $cleanedOptions[$name] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 1 |  |         return $cleanedOptions; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 1 |  |     public function getEvent() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 1 |  |         return $this->event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 3 |  |     public function setEvent($event) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 | 3 |  |         $this->event = $event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 1 |  |     public function getEventName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 1 |  |         return $this->eventName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 3 |  |     public function setEventName($eventName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 | 3 |  |         $this->eventName = $eventName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 1 |  |     public function getMeasure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 | 1 |  |         return $this->measure; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 3 |  |     public function setMeasure($measure) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 | 3 |  |         $this->measure = $measure; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 | 1 |  |     public function getMetricId() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 | 1 |  |         return $this->metricId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 3 |  |     public function setMetricId($metricId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 | 3 |  |         $this->metricId = $metricId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 3 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 163 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 164 | 1 |  |     public function getPriority() | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 166 | 1 |  |         return $this->priority; | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 | 3 |  |     public function setPriority($priority) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 3 |  |         $this->priority = $priority; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 | 1 |  |     public function getResults() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 | 1 |  |         return $this->results; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 3 |  |     public function setResults($results) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 3 |  |         $this->results = $results; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 | 1 |  |     public function getUnit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 | 1 |  |         return $this->unit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 | 3 |  |     public function setUnit($unit) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 | 3 |  |         $this->unit = $unit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 199 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 200 |  |  |  | 
            
                        
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.