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

Variation   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 152
ccs 58
cts 58
cp 1
rs 10
c 0
b 0
f 0
wmc 25
lcom 1
cbo 1

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getActions() 0 4 1
A setActions() 0 4 1
A getArchived() 0 4 1
A setArchived() 0 4 1
A getKey() 0 4 1
A setKey() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getVariationId() 0 4 1
A setVariationId() 0 4 1
A getWeight() 0 4 1
A setWeight() 0 4 1
B __construct() 0 21 9
B toArray() 0 24 4
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\Action;
10
11
/**
12
 * Optimizely variation.
13
 */
14
class Variation
15
{
16
    /**
17
     * A set of actions to take to apply the experiment when running
18
     * @var array[Actions]
19
     */
20
    private $actions;
21
    
22
    /**
23
     * Whether the variation is archived
24
     * @var boolean
25
     */
26
    private $archived;
27
    
28
    /**
29
     * Unique string identifier for this variation within the experiment
30
     * @var string
31
     */
32
    private $key;
33
    
34
    /**
35
     * The name of the variation
36
     * @var string
37
     */
38
    private $name;
39
    
40
    /**
41
     * The ID of the variation
42
     * @var type 
43
     */
44
    private $variationId;
45
    
46
    /**
47
     * The weight of the variation expressed as an integer between 0 and 10000. 
48
     * The weights of all varitions MUST add up to 10000 total (i.e. 100%)
49
     * @var integer 
50
     */
51
    private $weight;
52
    
53
    /**
54
     * Constructor.
55
     */
56 7
    public function __construct($options = array())
57
    {
58 7
        foreach ($options as $name=>$value) {
59
            switch ($name) {                
60 6
                case 'actions': {
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 6
                    $actions = array();
62 6
                    foreach ($value as $actionInfo) {
63 6
                        $actions[] = new Action($actionInfo);
64
                    }
65 6
                    $this->setActions($actions); break;
66
                }
67 6
                case 'archived': $this->setArchived($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...
68 6
                case 'key': $this->setKey($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 6
                case 'name': $this->setName($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...
70 6
                case 'variation_id': $this->setVariationId($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...
71 6
                case 'weight': $this->setWeight($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...
72
                default:
73 6
                    throw new \Exception('Unknown option: ' . $name);
74
            }
75
        }
76 7
    }
77
    
78
    /**
79
     * Returns this object as array.
80
     */
81 3
    public function toArray()
82
    {
83
        $options = array(
84 3
            'actions' => array(),
85 3
            'archived' => $this->getArchived(),
86 3
            'key' => $this->getKey(),
87 3
            'name' => $this->getName(),
88 3
            'variation_id' => $this->getVariationId(),
89 3
            'weight' => $this->getWeight()
90
        );
91
        
92 3
        foreach ($this->getActions() as $action) {
93 3
            $options['actions'][] = $action->toArray();
94
        }
95
        
96
        // Remove options with empty values
97 3
        $cleanedOptions = array();
98 3
        foreach ($options as $name=>$value) {
99 3
            if ($value!==null)
100 3
                $cleanedOptions[$name] = $value;
101
        }
102
        
103 3
        return $cleanedOptions;
104
    }
105
    
106 3
    public function getActions()
107
    {
108 3
        return $this->actions;
109
    }
110
    
111 7
    public function setActions($actions)
112
    {
113 7
        $this->actions = $actions;
114 7
    }
115
    
116 3
    public function getArchived()
117
    {
118 3
        return $this->archived;
119
    }
120
    
121 7
    public function setArchived($archived)
122
    {
123 7
        $this->archived = $archived;
124 7
    }
125
    
126 4
    public function getKey()
127
    {
128 4
        return $this->key;
129
    }
130
    
131 7
    public function setKey($key)
132
    {
133 7
        $this->key = $key;
134 7
    }
135
    
136 3
    public function getName()
137
    {
138 3
        return $this->name;
139
    }
140
    
141 7
    public function setName($name)
142
    {
143 7
        $this->name = $name;
144 7
    }
145
    
146 3
    public function getVariationId()
147
    {
148 3
        return $this->variationId;
149
    }
150
    
151 7
    public function setVariationId($variationId)
152
    {
153 7
        $this->variationId = $variationId;
154 7
    }
155
    
156 3
    public function getWeight()
157
    {
158 3
        return $this->weight;
159
    }
160
    
161 7
    public function setWeight($weight)
162
    {
163 7
        $this->weight = $weight;
164 7
    }
165
}
166
167
168
169
170
171
172
173
174
175