Completed
Push — master ( 0ca99d...7c70a3 )
by Oleg
02:52
created

CampaignMetricResults   A

Complexity

Total Complexity 28

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 95.89%

Importance

Changes 0
Metric Value
dl 0
loc 180
ccs 70
cts 73
cp 0.9589
rs 10
c 0
b 0
f 0
wmc 28
lcom 1
cbo 1

16 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 23 10
B toArray() 0 25 4
A getEvent() 0 4 1
A setEvent() 0 4 1
A getEventName() 0 4 1
A setEventName() 0 4 1
A getMeasure() 0 4 1
A setMeasure() 0 4 1
A getMetricId() 0 4 1
A setMetricId() 0 4 1
A getPriority() 0 4 1
A setPriority() 0 4 1
A getResults() 0 4 1
A setResults() 0 4 1
A getUnit() 0 4 1
A setUnit() 0 4 1
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;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
76 3
                case 'event_name': $this->setEventName($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
77 3
                case 'measure': $this->setMeasure($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
78 3
                case 'metric_id': $this->setMetricId($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
79 3
                case 'priority': $this->setPriority($value); break;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
80 3
                case 'results': {
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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;
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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) {
0 ignored issues
show
Bug introduced by
The expression $this->getResults() of type object<WebMarketingROI\O...urce\v2\VariantResults> is not traversable.
Loading history...
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