Completed
Push — master ( 04a13a...fed072 )
by James
05:24 queued 02:50
created

Variation::getWeight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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