Completed
Push — master ( ddef5e...4d3008 )
by Oleg
02:26
created

Metric::setWinningDirection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
     * The winning direction of this metric
52
     */
53
    private $winningDirection;
54
    
55
    /**
56
     * Constructor.
57
     */
58 14
    public function __construct($options = array())
59
    {
60 14
        foreach ($options as $name=>$value) {
61
            switch ($name) {                                
62 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...
63 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...
64 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...
65 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...
66
                case 'winning_direction' : $this->setWinningDirection($value);  break;
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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...
67
                default:
68 12
                    throw new Exception('Unknown option found in the Metric entity: ' . $name);
69
            }
70
        }
71 14
    }
72
    
73
    /**
74
     * Returns this object as array.
75
     */
76 6
    public function toArray()
77
    {
78
        $options = array(
79 6
            'event_id' => $this->getEventId(),    
80 6
            'aggregator' => $this->getAggregator(),
81 6
            'field' => $this->getField(),
82 6
            'scope' => $this->getScope(),
83 6
            'winning_direction' => $this->getWinningDirection(),
84
        );
85
        
86
        // Remove options with empty values
87 6
        $cleanedOptions = array();
88 6
        foreach ($options as $name=>$value) {
89 6
            if ($value!==null)
90 6
                $cleanedOptions[$name] = $value;
91
        }
92
        
93 6
        return $cleanedOptions;
94
    }
95
    
96 6
    public function getEventId()
97
    {
98 6
        return $this->eventId;
99
    }
100
    
101 14
    public function setEventId($eventId)
102
    {
103 14
        $this->eventId = $eventId;
104 14
    }
105
    
106 7
    public function getAggregator()
107
    {
108 7
        return $this->aggregator;
109
    }
110
    
111 14
    public function setAggregator($aggregator)
112
    {
113 14
        $this->aggregator = $aggregator;
114 14
    }
115
    
116 6
    public function getField()
117
    {
118 6
        return $this->field;
119
    }
120
    
121 14
    public function setField($field)
122
    {
123 14
        $this->field = $field;
124 14
    }
125
    
126 8
    public function getScope()
127
    {
128 8
        return $this->scope;
129
    }
130
    
131 14
    public function setScope($scope)
132
    {
133 14
        $this->scope = $scope;
134 14
    }
135
    
136 6
    public function getWinningDirection()
137
    {
138 6
        return $this->winningDirection;
139
    }
140
    
141
    public function setWinningDirection($winningDirection)
142
    {
143
        $this->winningDirection = $winningDirection;
144
    }
145
}
146
147
148
149
150
151