Completed
Push — master ( 39a82f...96059f )
by Oleg
02:54
created

UrlTargeting::__construct()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
eloc 11
c 0
b 0
f 0
nc 8
nop 1
dl 0
loc 16
ccs 0
cts 15
cp 0
crap 72
rs 7.7777
1
<?php
2
/**
3
 * @author Oleg Krivtsov <[email protected]>
4
 * @date 05 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 experiment.
13
 */
14
class UrlTargeting
15
{
16
    /**
17
     * Conditions to activate the experiment; our knowledge base article on 
18
     * Activation Types is the best guide for how to set up this data.
19
     * @var type 
20
     */
21
    private $conditions;
22
    
23
    /**
24
     * URL to load in the editor for this page
25
     * @var type 
26
     */
27
    private $editUrl;
28
    
29
    /**
30
     * Stringified Javascript function that determines when the Page is activated. 
31
     * Only required when activation_type is 'polling' or 'callback'.
32
     * @var type 
33
     */
34
    private $activationCode;
35
    
36
    /**
37
     * How this page is activated. See the full documentation on the Page object.
38
     * @var type 
39
     */
40
    private $activationType;
41
    
42
    /**
43
     * Unique string identifier for this Page within the Project
44
     * @var type 
45
     */
46
    private $key;
47
    
48
    /**
49
     * The unique identifier of the Page that represents the experiment or campaign's URL Targeting.
50
     * @var type 
51
     */
52
    private $pageId;
53
    
54
    /**
55
     * Constructor.
56
     */
57
    public function __construct($options = array())
58
    {
59
        foreach ($options as $name=>$value) {
60
            switch ($name) {
61
                case 'conditions': $this->setConditions($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...
62
                case 'edit_url': $this->setEditUrl($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
                case 'activation_code': $this->setActivationCode($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
                case 'activation_type': $this->setActivationType($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
                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...
66
                case 'page_id': $this->setPageId($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...
67
                
68
                default:
69
                    throw new Exception('Unknown option found in the UrlTargeting entity: ' . $name);
70
            }
71
        }
72
    }
73
    
74
    /**
75
     * Returns this object as array.
76
     */
77
    public function toArray()
78
    {
79
        $options = array(
0 ignored issues
show
Unused Code introduced by
$options is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
80
            'conditions' => $this->getConditions(),
81
            'edit_url' => $this->getEditUrl(),
82
            'activation_code' => $this->getActivationCode(),
83
            'activation_type' => $this->getActivationType(),
84
            'key' => $this->getKey(),
85
            'page_id' => $this->getPageId(),
86
        );
87
                
88
        return $cleanedOptions;
0 ignored issues
show
Bug introduced by
The variable $cleanedOptions does not exist. Did you mean $options?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
89
    }
90
    
91
    public function getConditions()
92
    {
93
        return $this->conditions;
94
    }
95
    
96
    public function setConditions($conditions)
97
    {
98
        $this->conditions = $conditions;
99
    }
100
    
101
    public function getEditUrl()
102
    {
103
        return $this->editUrl;
104
    }
105
    
106
    public function setEditUrl($editUrl)
107
    {
108
        $this->editUrl = $editUrl;
109
    }
110
    
111
    public function getActivationCode()
112
    {
113
        return $this->activationCode;
114
    }
115
    
116
    public function setActivationCode($activationCode)
117
    {
118
        $this->activationCode = $activationCode;
119
    }
120
    
121
    public function getActivationType()
122
    {
123
        return $this->activationType;
124
    }
125
    
126
    public function setActivationType($activationType)
127
    {
128
        $this->activationType = $activationType;
129
    }
130
    
131
    public function getKey()
132
    {
133
        return $this->key;
134
    }
135
    
136
    public function setKey($key)
137
    {
138
        $this->key = $key;
139
    }
140
    
141
    public function getPageId()
142
    {
143
        return $this->pageId;
144
    }
145
    
146
    public function setPageId($pageId)
147
    {
148
        $this->pageId = $pageId;
149
    }
150
}
151
152