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