Completed
Push — master ( 3b3e38...a670fe )
by James
04:00
created

Metric   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 115
ccs 38
cts 38
cp 1
rs 10
c 1
b 0
f 0
wmc 17
lcom 1
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getEventId() 0 4 1
A setEventId() 0 4 1
A getAggregator() 0 4 1
A setAggregator() 0 4 1
A getField() 0 4 1
A setField() 0 4 1
A getScope() 0 4 1
A setScope() 0 4 1
B __construct() 0 13 6
A toArray() 0 18 3
1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 10 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
 * An Optimizely campaign metric.
13
 */
14
class Metric
15
{
16
    /**
17
     * The ID for the Event to select data from. Omitted for global metrics that 
18
     * are not relative to a specific Event, i.e. "overall revenue"
19
     * @var integer 
20
     */
21
    private $eventId;
22
    
23
    /**
24
     * The aggregation function for the numerator of the metric. 'unique' measures 
25
     * the number of unique visitors/sessions that include the specified Event. 'count' measures the total number of occurrences of Event for the scope (visitor/session). 'sum' is the sum of the 'field' value
26
     * Can be unique, count or sum
27
     * @var type 
28
     */
29
    private $aggregator;
30
    
31
    /**
32
     * The field to aggregate for the numerator of the metric. Required when 'aggregator' = 'sum', otherwise omitted
33
     * Can be revenue or value
34
     * @var string
35
     */
36
    private $field;
37
    
38
    /**
39
     * Specifies how Events should be grouped together. Can also be thought of 
40
     * as the denonimator of the metric. 'session' divides by the number of sessions. 
41
     * "Influenced sessions", or sessions that do not contain a decision Event but 
42
     * carry a decision from a previous session are not included in counts for 
43
     * numerator or denominator. 'visitor' divides by the number of visitors. 
44
     * 'event' divides by the total occurrences (impressions) of the specified Event
45
     * Can be session, visitor or event
46
     * @var string 
47
     */
48
    private $scope;
49
    
50
    /**
51
     * Constructor.
52
     */
53 14
    public function __construct($options = array())
54
    {
55 14
        foreach ($options as $name=>$value) {
56
            switch ($name) {                                
57 12
                case 'event_id': $this->setEventId($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 12
                case 'aggregator': $this->setAggregator($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 12
                case 'field': $this->setField($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 12
                case 'scope': $this->setScope($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
                default:
62 12
                    throw new Exception('Unknown option found in the Metric entity: ' . $name);
63
            }
64
        }
65 14
    }
66
    
67
    /**
68
     * Returns this object as array.
69
     */
70 6
    public function toArray()
71
    {
72
        $options = array(
73 6
            'event_id' => $this->getEventId(),    
74 6
            'aggregator' => $this->getAggregator(),
75 6
            'field' => $this->getField(),
76 6
            'scope' => $this->getScope(),
77
        );
78
        
79
        // Remove options with empty values
80 6
        $cleanedOptions = array();
81 6
        foreach ($options as $name=>$value) {
82 6
            if ($value!==null)
83 6
                $cleanedOptions[$name] = $value;
84
        }
85
        
86 6
        return $cleanedOptions;
87
    }
88
    
89 6
    public function getEventId()
90
    {
91 6
        return $this->eventId;
92
    }
93
    
94 14
    public function setEventId($eventId)
95
    {
96 14
        $this->eventId = $eventId;
97 14
    }
98
    
99 7
    public function getAggregator()
100
    {
101 7
        return $this->aggregator;
102
    }
103
    
104 14
    public function setAggregator($aggregator)
105
    {
106 14
        $this->aggregator = $aggregator;
107 14
    }
108
    
109 6
    public function getField()
110
    {
111 6
        return $this->field;
112
    }
113
    
114 14
    public function setField($field)
115
    {
116 14
        $this->field = $field;
117 14
    }
118
    
119 8
    public function getScope()
120
    {
121 8
        return $this->scope;
122
    }
123
    
124 14
    public function setScope($scope)
125
    {
126 14
        $this->scope = $scope;
127 14
    }
128
}
129
130
131
132
133
134