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

ExperimentVariationReach::__construct()   C

Complexity

Conditions 9
Paths 9

Size

Total Lines 22
Code Lines 16

Duplication

Lines 8
Ratio 36.36 %

Code Coverage

Tests 16
CRAP Score 9.3188

Importance

Changes 0
Metric Value
cc 9
eloc 16
nc 9
nop 1
dl 8
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\VariationReach;
11
12
/**
13
 * Optimizely experiment variation reach.
14
 */
15
class ExperimentVariationReach
16
{
17
    /**
18
     * Baseline count
19
     * @var integer
20
     */
21
    private $baselineCount;
22
    
23
    /**
24
     * Baseline reach
25
     * @var number
26
     */
27
    private $baselineReach;
28
    
29
    /**
30
     * Total number of visitors exposed to the experiment
31
     * @var integer 
32
     */
33
    private $totalCount;
34
    
35
    /**
36
     * Treatment count
37
     * @var number
38
     */
39
    private $treatmentCount;
40
    
41
    /**
42
     * Treatment reach
43
     * @var number
44
     */
45
    private $treatmentReach;
46
    
47
    /**
48
     * A map of reach for each Variation keyed by Variation ID
49
     * @var array[VariationReach]
50
     */
51
    private $variations;
52
    
53
    /**
54
     * Constructor.
55
     */
56 3
    public function __construct($options = array())
57
    {
58 3
        foreach ($options as $name=>$value) {
59
            switch ($name) {                
60 3
                case 'baseline_count': $this->setBaselineCount($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...
61 3
                case 'baseline_reach': $this->setBaselineReach($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...
62 3
                case 'total_count': $this->setTotalCount($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...
63 3
                case 'treatment_count': $this->setTreatmentCount($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...
64 3
                case 'treatment_reach': $this->setTreatmentReach($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 View Code Duplication
                case 'variations': {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
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...
66 3
                    $variations = array();
67 3
                    foreach ($value as $name=>$variationInfo) {
68 3
                        $variations[$name] = new VariationReach($variationInfo);
69 3
                    }
70 3
                    $this->setVariations($variations); 
71 3
                    break;                
72
                }
73
                default:
74
                    throw new Exception('Unknown option: ' . $name);
75
            }
76 3
        }
77 3
    }
78
    
79
    /**
80
     * Returns this object as array.
81
     */
82 1
    public function toArray()
83
    {
84
        $options = array(
85 1
            'baseline_count' => $this->getBaselineCount(),
86 1
            'baseline_reach' => $this->getBaselineReach(),
87 1
            'total_count' => $this->getTotalCount(),
88 1
            'treatment_count' => $this->getTreatmentCount(),
89 1
            'treatment_reach' => $this->getTreatmentReach(),
90 1
            'variations' => array(),            
91 1
        );
92
        
93 1
        foreach ($this->getVariations() as $name=>$variation) {
94 1
            $options['variations'][$name] = $variation->toArray();
95 1
        }
96
        
97
        // Remove options with empty values
98 1
        $cleanedOptions = array();
99 1
        foreach ($options as $name=>$value) {
100 1
            if ($value!==null)
101 1
                $cleanedOptions[$name] = $value;
102 1
        }
103
        
104 1
        return $cleanedOptions;
105
    }
106
    
107 1
    public function getBaselineCount()
108
    {
109 1
        return $this->baselineCount;
110
    }
111
    
112 3
    public function setBaselineCount($baselineCount)
113
    {
114 3
        $this->baselineCount = $baselineCount;
115 3
    }
116
    
117 1
    public function getBaselineReach()
118
    {
119 1
        return $this->baselineReach;
120
    }
121
    
122 3
    public function setBaselineReach($baselineReach)
123
    {
124 3
        $this->baselineReach = $baselineReach;
125 3
    }
126
    
127 1
    public function getTotalCount()
128
    {
129 1
        return $this->totalCount;
130
    }
131
    
132 3
    public function setTotalCount($totalCount)
133
    {
134 3
        $this->totalCount = $totalCount;
135 3
    }
136
    
137 1
    public function getTreatmentCount()
138
    {
139 1
        return $this->treatmentCount;
140
    }
141
    
142 3
    public function setTreatmentCount($treatmentCount)
143
    {
144 3
        $this->treatmentCount = $treatmentCount;
145 3
    }
146
    
147 1
    public function getTreatmentReach()
148
    {
149 1
        return $this->treatmentReach;
150
    }
151
    
152 3
    public function setTreatmentReach($treatmentReach)
153
    {
154 3
        $this->treatmentReach = $treatmentReach;
155 3
    }
156
    
157 1
    public function getVariations()
158
    {
159 1
        return $this->variations;
160
    }
161
    
162 3
    public function setVariations($variations)
163
    {
164 3
        $this->variations = $variations;
165 3
    }
166
}
167
168
169
170
171
172
173
174
175
176
177
178