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

Datapoint   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 146
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
dl 0
loc 146
ccs 54
cts 57
cp 0.9474
rs 10
c 0
b 0
f 0
wmc 23
lcom 1
cbo 1

14 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 15 8
A toArray() 0 20 3
A getConfidenceInterval() 0 4 1
A setConfidenceInterval() 0 4 1
A getIsMostConclusive() 0 4 1
A setIsMostConclusive() 0 4 1
A getIsSignificant() 0 4 1
A setIsSignificant() 0 4 1
A getSignificance() 0 4 1
A setSignificance() 0 4 1
A getValue() 0 4 1
A setValue() 0 4 1
A getVisitorsRemaining() 0 4 1
A setVisitorsRemaining() 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\Exception;
10
11
/**
12
 * Optimizely datapoint.
13
 */
14
class Datapoint
15
{
16
    /**
17
     * The confidence interval measures the uncertainty around improvement. It 
18
     * starts out wide and shrinks as more data comes in. Significance means 
19
     * that the confidence interval is completely above or completely below 0. 
20
     * If the result is significant and positive, the confidence interval will 
21
     * be above 0. If the result is significant and negative, confidence interval 
22
     * will be below 0. If the result is inconclusive, confidence interval includes 0.
23
     * @var array[number]
24
     */
25
    private $confidenceInterval;
26
    
27
    /**
28
     * Indicates that this is the best performing variant for this metric. 
29
     * Also referred to as the 'Winner'
30
     * @var boolean 
31
     */
32
    private $isMostConclusive;
33
    
34
    /**
35
     * Indicates if significance is above your confidence threshold
36
     * @var boolean
37
     */
38
    private $isSignificant;
39
    
40
    /**
41
     * The likelihood that the observed difference in conversion rate is not due to chance.
42
     * @var number 
43
     */
44
    private $significance;
45
    
46
    /**
47
     * The relative improvement for this variant over the baseline variant.
48
     * @var number
49
     */
50
    private $value;
51
    
52
    /**
53
     * The number of estimated visitors remaining before result becomes statistically significant
54
     * @var integer 
55
     */
56
    private $visitorsRemaining;
57
    /**
58
     * Constructor.
59
     */
60 3
    public function __construct($options = array())
61
    {
62 3
        foreach ($options as $name=>$value) {
63
            switch ($name) {                
64 3
                case 'confidence_interval': $this->setConfidenceInterval($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 'is_most_conclusive': $this->setIsMostConclusive($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 'is_significant': $this->setIsSignificant($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 'significance': $this->setSignificance($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...
68 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...
69 3
                case 'visitors_remaining': $this->setVisitorsRemaining($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...
70
                default:
71
                    throw new Exception('Unknown option found in the Datapoint entity: ' . $name);
72
            }
73 3
        }
74 3
    }
75
    
76
    /**
77
     * Returns this object as array.
78
     */
79 1
    public function toArray()
80
    {
81
        $options = array(
82 1
            'confidence_interval' => $this->getConfidenceInterval(),
83 1
            'is_most_conclusive' => $this->getIsMostConclusive(),
84 1
            'is_significant' => $this->getIsSignificant(),
85 1
            'significance' => $this->getSignificance(),
86 1
            'value' => $this->getValue(),            
87 1
            'visitors_remaining' => $this->getVisitorsRemaining(),            
88 1
        );
89
        
90
        // Remove options with empty values
91 1
        $cleanedOptions = array();
92 1
        foreach ($options as $name=>$value) {
93 1
            if ($value!==null)
94 1
                $cleanedOptions[$name] = $value;
95 1
        }
96
        
97 1
        return $cleanedOptions;
98
    }
99
    
100 1
    public function getConfidenceInterval()
101
    {
102 1
        return $this->confidenceInterval;
103
    }
104
    
105 3
    public function setConfidenceInterval($confidenceInterval)
106
    {
107 3
        $this->confidenceInterval = $confidenceInterval;
108 3
    }
109
    
110 1
    public function getIsMostConclusive()
111
    {
112 1
        return $this->isMostConclusive;
113
    }
114
    
115 3
    public function setIsMostConclusive($isMostConclusive)
116
    {
117 3
        $this->isMostConclusive = $isMostConclusive;
118 3
    }
119
    
120 1
    public function getIsSignificant()
121
    {
122 1
        return $this->isSignificant;
123
    }
124
    
125 3
    public function setIsSignificant($isSignificant)
126
    {
127 3
        $this->isSignificant = $isSignificant;
128 3
    }
129
    
130 1
    public function getSignificance()
131
    {
132 1
        return $this->significance;
133
    }
134
    
135 3
    public function setSignificance($significance)
136
    {
137 3
        $this->significance = $significance;
138 3
    }
139
    
140 1
    public function getValue()
141
    {
142 1
        return $this->value;
143
    }
144
    
145 3
    public function setValue($value)
146
    {
147 3
        $this->value = $value;
148 3
    }
149
    
150 1
    public function getVisitorsRemaining()
151
    {
152 1
        return $this->visitorsRemaining;
153
    }
154
    
155 3
    public function setVisitorsRemaining($visitorsRemaining)
156
    {
157 3
        $this->visitorsRemaining = $visitorsRemaining;
158 3
    }
159
}
160
161
162
163
164
165
166
167
168