Completed
Push — master ( 96059f...fe2237 )
by Oleg
06:07
created

ExperimentResults::__construct()   C

Complexity

Conditions 9
Paths 9

Size

Total Lines 22
Code Lines 16

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 16
CRAP Score 9.3188

Importance

Changes 0
Metric Value
cc 9
eloc 16
nc 9
nop 1
dl 22
loc 22
ccs 16
cts 19
cp 0.8421
crap 9.3188
rs 6.412
c 0
b 0
f 0
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
use WebMarketingROI\OptimizelyPHP\Resource\v2\ExperimentMetricResults;
11
use WebMarketingROI\OptimizelyPHP\Resource\v2\ExperimentVariationReach;
12
13
/**
14
 * Optimizely experiment results.
15
 */
16
class ExperimentResults
17
{
18
    /**
19
     * The significance level at which you would like to declare winning and 
20
     * losing variations. A lower number minimizes the time needed to declare 
21
     * a winning or losing variation, but increases the risk that your results 
22
     * aren't true winners and losers.
23
     * @var number
24
     */
25
    private $confidenceThreshold;
26
    
27
    /**
28
     * The latest time to count events in results
29
     * @var string
30
     */
31
    private $endTime;
32
    
33
    /**
34
     * The unique identifier for the Experiment.
35
     * @var type 
36
     */
37
    private $experimentId;
38
    
39
    /**
40
     * The breakdown of experiment results by metric
41
     * @var array[ExperimentMetricResult]
42
     */
43
    private $metrics;
44
    
45
    /**
46
     * The total number of users exposed to a different experience
47
     * @var ExperimentVariationReach
48
     */
49
    private $reach;
50
    
51
    /**
52
     * The earliest time to count events in results
53
     * @var string 
54
     */
55
    private $startTime;
56
    
57
    /**
58
     * Constructor.
59
     */
60 3 View Code Duplication
    public function __construct($options = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62 3
        foreach ($options as $name=>$value) {
63
            switch ($name) {                
64 3
                case 'confidence_threshold': $this->setConfidenceThreshold($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...
65 3
                case 'end_time': $this->setEndTime($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...
66 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...
67 3
                case 'metrics': {
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...
68 3
                    $metrics = array();
69 3
                    foreach ($value as $metricInfo) {
70 3
                        $metrics[] = new ExperimentMetricResults($metricInfo);                        
71 3
                    }
72 3
                    $this->setMetrics($metrics); 
73 3
                    break;
74
                }
75 3
                case 'reach': $this->setReach(new ExperimentVariationReach($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 'start_time': $this->setStartTime($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
                default:
78
                    throw new Exception('Unknown option found in the ExperimentVariationReach entity: ' . $name);
79
            }
80 3
        }
81 3
    }
82
    
83
    /**
84
     * Returns this object as array.
85
     */
86 1
    public function toArray()
87
    {
88
        $options = array(
89 1
            'confidence_threshold' => $this->getConfidenceThreshold(),
90 1
            'end_time' => $this->getEndTime(),
91 1
            'experiment_id' => $this->getExperimentId(),
92 1
            'metrics' => array(),
93 1
            'reach' => $this->getReach()?$this->getReach()->toArray():null,
94 1
            'start_time' => $this->getStartTime()
95 1
        );
96
        
97 1
        foreach ($this->getMetrics() as $metric) {
98 1
            $options['metrics'][] = $metric->toArray();
99 1
        }
100
        
101
        // Remove options with empty values
102 1
        $cleanedOptions = array();
103 1
        foreach ($options as $name=>$value) {
104 1
            if ($value!==null)
105 1
                $cleanedOptions[$name] = $value;
106 1
        }
107
        
108 1
        return $cleanedOptions;
109
    }
110
    
111 3
    public function getConfidenceThreshold()
112
    {
113 3
        return $this->confidenceThreshold;
114
    }
115
    
116 3
    public function setConfidenceThreshold($confidenceThreshold)
117
    {
118 3
        $this->confidenceThreshold = $confidenceThreshold;
119 3
    }
120
    
121 1
    public function getEndTime()
122
    {
123 1
        return $this->endTime;
124
    }
125
    
126 3
    public function setEndTime($endTime)
127
    {
128 3
        $this->endTime = $endTime;
129 3
    }
130
    
131 1
    public function getExperimentId()
132
    {
133 1
        return $this->experimentId;
134
    }
135
    
136 3
    public function setExperimentId($experimentId)
137
    {
138 3
        $this->experimentId = $experimentId;
139 3
    }
140
    
141 1
    public function getMetrics()
142
    {
143 1
        return $this->metrics;
144
    }
145
    
146 3
    public function setMetrics($metrics)
147
    {
148 3
        $this->metrics = $metrics;
149 3
    }
150
    
151 1
    public function getReach()
152
    {
153 1
        return $this->reach;
154
    }
155
    
156 3
    public function setReach($reach)
157
    {
158 3
        $this->reach = $reach;
159 3
    }
160
    
161 2
    public function getStartTime()
162
    {
163 2
        return $this->startTime;
164
    }
165
    
166 3
    public function setStartTime($startTime)
167
    {
168 3
        $this->startTime = $startTime;
169 3
    }
170
}
171
172
173
174
175
176
177
178
179
180
181