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

CampaignResults::__construct()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 21
Code Lines 15

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 15
CRAP Score 8.2964

Importance

Changes 0
Metric Value
cc 8
eloc 15
nc 8
nop 1
dl 21
loc 21
ccs 15
cts 18
cp 0.8333
crap 8.2964
rs 7.1428
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\CampaignMetricResults;
11
12
/**
13
 * Optimizely campaign results.
14
 */
15
class CampaignResults
16
{
17
    /**
18
     * The unique identifier for the Campaign
19
     * @var integer
20
     */
21
    private $campaignId;
22
    
23
    /**
24
     * The significance level at which you would like to declare winning and 
25
     * losing variations. A lower number minimizes the time needed to declare a 
26
     * winning or losing variation, but increases the risk that your results 
27
     * aren't true winners and losers.
28
     * @var number
29
     */
30
    private $confidenceThreshold;
31
    
32
    /**
33
     * The latest time to count events in results
34
     * @var string 
35
     */
36
    private $endTime;
37
    
38
    /**
39
     * The breakdown of campaign results by metric.
40
     * @var array[CampaignMetricResults]
41
     */
42
    private $metrics;
43
    
44
    /**
45
     * The earliest time to count events in results
46
     * @var string
47
     */
48
    private $startTime;
49
    
50
    /**
51
     * Constructor.
52
     */
53 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...
54
    {
55 3
        foreach ($options as $name=>$value) {
56
            switch ($name) {                
57 3
                case 'campaign_id': $this->setCampaignId($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...
58 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...
59 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...
60 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...
61 3
                    $metrics = array();
62 3
                    foreach ($value as $metricInfo) {
63 3
                        $metrics[] = new CampaignMetricResults($metricInfo);
64 3
                    }
65 3
                    $this->setMetrics($metrics); 
66 3
                    break;
67
                }
68 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...
69
                default:
70
                    throw new Exception('Unknown option found in CampaignResults entity: ' . $name);
71
            }
72 3
        }
73 3
    }
74
    
75
    /**
76
     * Returns this object as array.
77
     */
78 2
    public function toArray()
79
    {
80
        $options = array(
81 1
            'campaign_id' => $this->getCampaignId(),
82 1
            'confidence_threshold' => $this->getConfidenceThreshold(),
83 1
            'end_time' => $this->getEndTime(),
84 2
            'metrics' => array(),
85 1
            'start_time' => $this->getStartTime()
86 1
        );
87
        
88 1
        foreach ($this->getMetrics() as $metric) {
89 1
            $options['metrics'][] = $metric->toArray();
90 1
        }
91
        
92
        // Remove options with empty values
93 1
        $cleanedOptions = array();
94 1
        foreach ($options as $name=>$value) {
95 1
            if ($value!==null)
96 1
                $cleanedOptions[$name] = $value;
97 1
        }
98
        
99 1
        return $cleanedOptions;
100
    }
101
    
102 1
    public function getCampaignId()
103
    {
104 1
        return $this->campaignId;
105
    }
106
    
107 3
    public function setCampaignId($campaignId)
108
    {
109 3
        $this->campaignId = $campaignId;
110 3
    }
111
    
112 3
    public function getConfidenceThreshold()
113
    {
114 3
        return $this->confidenceThreshold;
115
    }
116
    
117 3
    public function setConfidenceThreshold($confidenceThreshold)
118
    {
119 3
        $this->confidenceThreshold = $confidenceThreshold;
120 3
    }
121
    
122 1
    public function getEndTime()
123
    {
124 1
        return $this->endTime;
125
    }
126
    
127 3
    public function setEndTime($endTime)
128
    {
129 3
        $this->endTime = $endTime;
130 3
    }
131
    
132 1
    public function getMetrics()
133
    {
134 1
        return $this->metrics;
135
    }
136
    
137 3
    public function setMetrics($metrics)
138
    {
139 3
        $this->metrics = $metrics;
140 3
    }
141
    
142 3
    public function getStartTime()
143
    {
144 3
        return $this->startTime;
145
    }
146
    
147 3
    public function setStartTime($startTime)
148
    {
149 3
        $this->startTime = $startTime;
150 3
    }
151
}
152
153
154
155
156