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

VariantResults   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 198
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 96.15%

Importance

Changes 0
Metric Value
dl 0
loc 198
ccs 75
cts 78
cp 0.9615
rs 9.2
c 0
b 0
f 0
wmc 34
lcom 1
cbo 1

20 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 18 11
B toArray() 0 23 5
A getExperimentId() 0 4 1
A setExperimentId() 0 4 1
A getIsBaseline() 0 4 1
A setIsBaseline() 0 4 1
A getLift() 0 4 1
A setLift() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getRate() 0 4 1
A setRate() 0 4 1
A getScope() 0 4 1
A setScope() 0 4 1
A getTotalIncrease() 0 4 1
A setTotalIncrease() 0 4 1
A getValue() 0 4 1
A setValue() 0 4 1
A getVariationId() 0 4 1
A setVariationId() 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\Datapoint;
10
11
/**
12
 * Optimizely campaign variant results.
13
 */
14
class VariantResults
15
{
16
    /**
17
     * The unique identifier for the Experiment this entity contains results for (if applicable).
18
     * @var integer 
19
     */
20
    private $experimentId;
21
    
22
    /**
23
     * Indicates that this variant is the baseline that all other entities will 
24
     * be compared against. Also referred to as the 'Control' or 'Control Group'.
25
     * @var boolean
26
     */
27
    private $isBaseline;
28
    
29
    /**
30
     * The relative difference in performance of this variant vs. the baseline 
31
     * variant. Lift is calculated as follows: (Winning Conversion Rate % - Old 
32
     * Conversion Rate %) - Old Conversion Rate % = % Improvement
33
     * @var Datapoint
34
     */
35
    private $lift;
36
    
37
    /**
38
     * The name of the variant
39
     * @var string
40
     */
41
    private $name;
42
    
43
    /**
44
     *
45
     * @var number
46
     */
47
    private $rate;
48
    
49
    /**
50
     * The scope that this variant represents. Can be 'variation', 'experiment' or 'campaign'
51
     * @var string 
52
     */
53
    private $scope;
54
    
55
    /**
56
     *
57
     * @var Datapoint
58
     */
59
    private $totalIncrease;
60
    
61
    /**
62
     *
63
     * @var number
64
     */
65
    private $value;
66
    
67
    /**
68
     * 
69
     * @var string 
70
     */
71
    private $variationId;
72
    
73
    /**
74
     * Constructor.
75
     */
76 3
    public function __construct($options = array())
77
    {
78 3
        foreach ($options as $name=>$value) {
79
            switch ($name) {                
80 3
                case 'experiment_id': $this->setExperimentId($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...
81 3
                case 'is_baseline': $this->setIsBaseline($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...
82 3
                case 'lift': $this->setLift(new Datapoint($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...
83 3
                case 'name': $this->setName($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...
84 3
                case 'rate': $this->setRate($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...
85 3
                case 'scope': $this->setScope($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...
86 3
                case 'total_increase': $this->setTotalIncrease(new Datapoint($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...
87 3
                case 'value': $this->setValue($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...
88 3
                case 'variation_id': $this->setVariationId($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
            'experiment_id' => $this->getExperimentId(),
102 1
            'is_baseline' => $this->getIsBaseline(),
103 1
            'lift' => $this->getLift()?$this->getLift()->toArray():null,
104 1
            'name' => $this->getName(),
105 1
            'rate' => $this->getRate(),
106 1
            'scope' => $this->getScope(),
107 1
            'total_increase' => $this->getTotalIncrease()?$this->getTotalIncrease()->toArray():null,
108 1
            'value' => $this->getValue(),
109 1
            'variation_id' => $this->getVariationId()
110 1
        );
111
        
112
        // Remove options with empty values
113 1
        $cleanedOptions = array();
114 1
        foreach ($options as $name=>$value) {
115 1
            if ($value!==null)
116 1
                $cleanedOptions[$name] = $value;
117 1
        }
118
        
119 1
        return $cleanedOptions;
120
    }
121
    
122 1
    public function getExperimentId()
123
    {
124 1
        return $this->experimentId;
125
    }
126
    
127 3
    public function setExperimentId($experimentId)
128
    {
129 3
        $this->experimentId = $experimentId;
130 3
    }
131
    
132 1
    public function getIsBaseline()
133
    {
134 1
        return $this->isBaseline;
135
    }
136
    
137 3
    public function setIsBaseline($isBaseline)
138
    {
139 3
        $this->isBaseline = $isBaseline;
140 3
    }
141
    
142 1
    public function getLift()
143
    {
144 1
        return $this->lift;
145
    }
146
    
147 3
    public function setLift($lift)
148
    {
149 3
        $this->lift = $lift;
150 3
    }
151
    
152 1
    public function getName()
153
    {
154 1
        return $this->name;
155
    }
156
    
157 3
    public function setName($name)
158
    {
159 3
        $this->name = $name;
160 3
    }
161
    
162 1
    public function getRate()
163
    {
164 1
        return $this->rate;
165
    }
166
    
167 3
    public function setRate($rate)
168
    {
169 3
        $this->rate = $rate;
170 3
    }
171
    
172 1
    public function getScope()
173
    {
174 1
        return $this->scope;
175
    }
176
    
177 3
    public function setScope($scope)
178
    {
179 3
        $this->scope = $scope;
180 3
    }
181
    
182 1
    public function getTotalIncrease()
183
    {
184 1
        return $this->totalIncrease;
185
    }
186
    
187 3
    public function setTotalIncrease($totalIncrease)
188
    {
189 3
        $this->totalIncrease = $totalIncrease;
190 3
    }
191
    
192 1
    public function getValue()
193
    {
194 1
        return $this->value;
195
    }
196
    
197 3
    public function setValue($value)
198
    {
199 3
        $this->value = $value;
200 3
    }
201
    
202 1
    public function getVariationId()
203
    {
204 1
        return $this->variationId;
205
    }
206
    
207 3
    public function setVariationId($variationId)
208
    {
209 3
        $this->variationId = $variationId;
210 3
    }
211
}
212
213
214
215
216
217
218
219
220