Completed
Push — master ( 555df9...68d1eb )
by Oleg
03:17
created

Variation::getDescription()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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
     * Current status of the variation
56
     * @var string 
57
     */
58
    private $status;
59
    
60
    /**
61
     * A description of the variation.
62
     * @var type 
63
     */
64
    private $description;
65
    
66
    /**
67
     * Constructor.
68
     */
69 7
    public function __construct($options = array())
70
    {
71 7
        foreach ($options as $name=>$value) {
72
            switch ($name) {                
73 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...
74 6
                    $actions = array();
75 6
                    foreach ($value as $actionInfo) {
76 6
                        $actions[] = new Action($actionInfo);
77
                    }
78 6
                    $this->setActions($actions); break;
79
                }
80 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...
81 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...
82 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...
83 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...
84 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...
85
                case 'status': $this->setStatus($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...
86
                case 'description': $this->setDescription($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...
87
                default:
88 6
                    throw new Exception('Unknown option found in the Variation entity: ' . $name);
89
            }
90
        }
91 7
    }
92
    
93
    /**
94
     * Returns this object as array.
95
     */
96 3
    public function toArray()
97
    {
98
        $options = array(
99 3
            'actions' => array(),
100 3
            'archived' => $this->getArchived(),
101 3
            'key' => $this->getKey(),
102 3
            'name' => $this->getName(),
103 3
            'variation_id' => $this->getVariationId(),
104 3
            'weight' => $this->getWeight(),
105 3
            'status' => $this->getStatus(),
106 3
            'description' => $this->getDescription(),
107
        );
108
        
109 3
        foreach ($this->getActions() as $action) {
110 3
            $options['actions'][] = $action->toArray();
111
        }
112
        
113
        // Remove options with empty values
114 3
        $cleanedOptions = array();
115 3
        foreach ($options as $name=>$value) {
116 3
            if ($value!==null)
117 3
                $cleanedOptions[$name] = $value;
118
        }
119
        
120 3
        return $cleanedOptions;
121
    }
122
    
123 3
    public function getActions()
124
    {
125 3
        return $this->actions;
126
    }
127
    
128 7
    public function setActions($actions)
129
    {
130 7
        $this->actions = $actions;
131 7
    }
132
    
133 3
    public function getArchived()
134
    {
135 3
        return $this->archived;
136
    }
137
    
138 7
    public function setArchived($archived)
139
    {
140 7
        $this->archived = $archived;
141 7
    }
142
    
143 4
    public function getKey()
144
    {
145 4
        return $this->key;
146
    }
147
    
148 7
    public function setKey($key)
149
    {
150 7
        $this->key = $key;
151 7
    }
152
    
153 3
    public function getName()
154
    {
155 3
        return $this->name;
156
    }
157
    
158 7
    public function setName($name)
159
    {
160 7
        $this->name = $name;
161 7
    }
162
    
163 3
    public function getVariationId()
164
    {
165 3
        return $this->variationId;
166
    }
167
    
168 7
    public function setVariationId($variationId)
169
    {
170 7
        $this->variationId = $variationId;
171 7
    }
172
    
173 3
    public function getWeight()
174
    {
175 3
        return $this->weight;
176
    }
177
    
178 7
    public function setWeight($weight)
179
    {
180 7
        $this->weight = $weight;
181 7
    }
182
    
183 3
    public function getStatus()
184
    {
185 3
        return $this->status;
186
    }
187
    
188
    public function setStatus($status)
189
    {
190
        $this->status = $status;
191
    }
192
    
193 3
    public function getDescription()
194
    {
195 3
        return $this->description;
196
    }
197
    
198
    public function setDescription($description)
199
    {
200
        $this->description = $description;
201
    }
202
}
203
204
205
206
207
208
209
210
211
212