Completed
Push — develop ( 6fdb58...dee5cf )
by Oleg
04:27 queued 01:45
created

ExperimentResults   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 155
Duplicated Lines 14.19 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 22
loc 155
ccs 58
cts 58
cp 1
rs 10
c 0
b 0
f 0
wmc 26
lcom 1
cbo 2

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfidenceThreshold() 0 4 1
A setConfidenceThreshold() 0 4 1
A getEndTime() 0 4 1
A setEndTime() 0 4 1
A getExperimentId() 0 4 1
A setExperimentId() 0 4 1
A getMetrics() 0 4 1
A setMetrics() 0 4 1
A getReach() 0 4 1
A setReach() 0 4 1
A getStartTime() 0 4 1
A setStartTime() 0 4 1
C __construct() 22 22 9
B toArray() 0 24 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\ExperimentMetricResults;
10
use WebMarketingROI\OptimizelyPHP\Resource\v2\ExperimentVariationReach;
11
12
/**
13
 * Optimizely experiment results.
14
 */
15
class ExperimentResults
16
{
17
    /**
18
     * The significance level at which you would like to declare winning and 
19
     * losing variations. A lower number minimizes the time needed to declare 
20
     * a winning or losing variation, but increases the risk that your results 
21
     * aren't true winners and losers.
22
     * @var number
23
     */
24
    private $confidenceThreshold;
25
    
26
    /**
27
     * The latest time to count events in results
28
     * @var string
29
     */
30
    private $endTime;
31
    
32
    /**
33
     * The unique identifier for the Experiment.
34
     * @var type 
35
     */
36
    private $experimentId;
37
    
38
    /**
39
     * The breakdown of experiment results by metric
40
     * @var array[ExperimentMetricResult]
41
     */
42
    private $metrics;
43
    
44
    /**
45
     * The total number of users exposed to a different experience
46
     * @var ExperimentVariationReach
47
     */
48
    private $reach;
49
    
50
    /**
51
     * The earliest time to count events in results
52
     * @var string 
53
     */
54
    private $startTime;
55
    
56
    /**
57
     * Constructor.
58
     */
59 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...
60
    {
61 3
        foreach ($options as $name=>$value) {
62
            switch ($name) {                
63 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...
64 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...
65 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...
66 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...
67 3
                    $metrics = array();
68 3
                    foreach ($value as $metricInfo) {
69 3
                        $metrics[] = new ExperimentMetricResults($metricInfo);                        
70
                    }
71 3
                    $this->setMetrics($metrics); 
72 3
                    break;
73
                }
74 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...
75 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...
76
                default:
77 3
                    throw new \Exception('Unknown option: ' . $name);
78
            }
79
        }
80 3
    }
81
    
82
    /**
83
     * Returns this object as array.
84
     */
85 1
    public function toArray()
86
    {
87
        $options = array(
88 1
            'confidence_threshold' => $this->getConfidenceThreshold(),
89 1
            'end_time' => $this->getEndTime(),
90 1
            'experiment_id' => $this->getExperimentId(),
91
            'metrics' => array(),
92 1
            'reach' => $this->getReach()?$this->getReach()->toArray():null,
93 1
            'start_time' => $this->getStartTime()
94
        );
95
        
96 1
        foreach ($this->getMetrics() as $metric) {
97 1
            $options['metrics'][] = $metric->toArray();
98
        }
99
        
100
        // Remove options with empty values
101 1
        $cleanedOptions = array();
102 1
        foreach ($options as $name=>$value) {
103 1
            if ($value!==null)
104 1
                $cleanedOptions[$name] = $value;
105
        }
106
        
107 1
        return $cleanedOptions;
108
    }
109
    
110 3
    public function getConfidenceThreshold()
111
    {
112 3
        return $this->confidenceThreshold;
113
    }
114
    
115 3
    public function setConfidenceThreshold($confidenceThreshold)
116
    {
117 3
        $this->confidenceThreshold = $confidenceThreshold;
118 3
    }
119
    
120 1
    public function getEndTime()
121
    {
122 1
        return $this->endTime;
123
    }
124
    
125 3
    public function setEndTime($endTime)
126
    {
127 3
        $this->endTime = $endTime;
128 3
    }
129
    
130 1
    public function getExperimentId()
131
    {
132 1
        return $this->experimentId;
133
    }
134
    
135 3
    public function setExperimentId($experimentId)
136
    {
137 3
        $this->experimentId = $experimentId;
138 3
    }
139
    
140 1
    public function getMetrics()
141
    {
142 1
        return $this->metrics;
143
    }
144
    
145 3
    public function setMetrics($metrics)
146
    {
147 3
        $this->metrics = $metrics;
148 3
    }
149
    
150 1
    public function getReach()
151
    {
152 1
        return $this->reach;
153
    }
154
    
155 3
    public function setReach($reach)
156
    {
157 3
        $this->reach = $reach;
158 3
    }
159
    
160 2
    public function getStartTime()
161
    {
162 2
        return $this->startTime;
163
    }
164
    
165 3
    public function setStartTime($startTime)
166
    {
167 3
        $this->startTime = $startTime;
168 3
    }
169
}
170
171
172
173
174
175
176
177
178
179
180