Completed
Push — master ( 0ca99d...7c70a3 )
by Oleg
02:52
created

WebSnippet   A

Complexity

Total Complexity 35

Size/Duplication

Total Lines 220
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 96.47%

Importance

Changes 0
Metric Value
dl 0
loc 220
ccs 82
cts 85
cp 0.9647
rs 9
c 0
b 0
f 0
wmc 35
lcom 1
cbo 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 19 12
B toArray() 0 24 3
A getEnableForceVariation() 0 4 1
A setEnableForceVariation() 0 4 1
A getExcludeDisabledExperiments() 0 4 1
A setExcludeDisabledExperiments() 0 4 1
A getExcludeNames() 0 4 1
A setExcludeNames() 0 4 1
A getIncludeJquery() 0 4 1
A setIncludeJquery() 0 4 1
A getIpAnonymization() 0 4 1
A setIpAnonymization() 0 4 1
A getIpFilter() 0 4 1
A setIpFilter() 0 4 1
A getLibrary() 0 4 1
A setLibrary() 0 4 1
A getProjectJavascript() 0 4 1
A setProjectJavascript() 0 4 1
A getCodeRevision() 0 4 1
A setCodeRevision() 0 4 1
A getJsFileSize() 0 4 1
A setJsFileSize() 0 4 1
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
/**
10
 * An Optimizely web snippet configuration.
11
 */
12
class WebSnippet
13
{
14
    /**
15
     * Enables the option to force yourself into a specific Variation on any page
16
     * @var boolean 
17
     */
18
    private $enableForceVariation;
19
    
20
    /**
21
     * Set to true to remove paused and draft experiments from the snippet
22
     * @var boolean 
23
     */
24
    private $excludeDisabledExperiments;
25
    
26
    /**
27
     * Set to true to mask descriptive names
28
     * @var boolean
29
     */
30
    private $excludeNames;
31
    
32
    /**
33
     * Set to true to include jQuery in your snippet.
34
     * @var boolean 
35
     */
36
    private $includeJquery;
37
    
38
    /**
39
     * Set to true to change the last octet of IP addresses to 0 prior to logging
40
     * @var boolean 
41
     */
42
    private $ipAnonymization;
43
    
44
    /**
45
     * A regular expression (max 1500 characters) matching ip addresses for 
46
     * filtering out visitors. Matching visitors will still see the experiments, 
47
     * but they won't be counted in results.
48
     * @var string 
49
     */
50
    private $ipFilter;
51
    
52
    /**
53
     * The prefered jQuery library version you would like to use with your snippet. 
54
     * If you do not want to include jQuery, set include_jquery to false. Can be 
55
     * 'jquery-1.11.3-trim', 'jquery-1.11.3-full', 'jquery-1.6.4-trim', 'jquery-1.6.4-full' 
56
     * or 'none'.
57
     * @var string 
58
     */
59
    private $library;
60
    
61
    /**
62
     * The javascript code which runs before Optimizely on all pages, regardless 
63
     * of whether or not there is a running experiment.
64
     * @var string
65
     */
66
    private $projectJavascript;
67
    
68
    /**
69
     * The current revision number of the project snippet
70
     * @var integer 
71
     */
72
    private $codeRevision;
73
    
74
    /**
75
     * The current size in bytes of the project snippet
76
     * @var integer 
77
     */
78
    private $jsFileSize;
79
    
80
    
81
    /**
82
     * Constructor.
83
     */
84 7
    public function __construct($options = array())
85
    {
86 7
        foreach ($options as $name=>$value) {
87
            switch ($name) {                
88 6
                case 'enable_force_variation': $this->setEnableForceVariation($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...
89 6
                case 'exclude_disabled_experiments': $this->setExcludeDisabledExperiments($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...
90 6
                case 'exclude_names': $this->setExcludeNames($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...
91 6
                case 'include_jquery': $this->setIncludeJquery($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...
92 6
                case 'ip_anonymization': $this->setIpAnonymization($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...
93 6
                case 'ip_filter': $this->setIpFilter($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...
94 6
                case 'library': $this->setLibrary($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...
95 6
                case 'project_javascript': $this->setProjectJavascript($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...
96 6
                case 'code_revision': $this->setCodeRevision($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...
97 6
                case 'js_file_size': $this->setJsFileSize($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...
98
                default:
99
                    throw new \Exception('Unknown option: ' . $name);
100
            }
101 7
        }
102 7
    }
103
    
104
    /**
105
     * Returns this object as array.
106
     */
107 3
    public function toArray()
108
    {
109
        $options = array(
110 3
            'enable_force_variation' => $this->enableForceVariation,
111 3
            'exclude_disabled_experiments' => $this->excludeDisabledExperiments,
112 3
            'exclude_names' => $this->excludeNames,
113 3
            'include_jquery' => $this->includeJquery,
114 3
            'ip_anonymization' => $this->ipAnonymization,
115 3
            'ip_filter' => $this->ipFilter,
116 3
            'library' => $this->library,
117 3
            'project_javascript' => $this->projectJavascript,
118 3
            'code_revision' => $this->codeRevision,
119 3
            'js_file_size' => $this->jsFileSize
120 3
        );
121
        
122
        // Remove options with empty values
123 3
        $cleanedOptions = array();
124 3
        foreach ($options as $name=>$value) {
125 3
            if ($value!==null)
126 3
                $cleanedOptions[$name] = $value;
127 3
        }
128
        
129 3
        return $cleanedOptions;
130
    }
131
    
132 1
    public function getEnableForceVariation()
133
    {
134 1
        return $this->enableForceVariation;
135
    }
136
    
137 7
    public function setEnableForceVariation($enableForceVariation)
138
    {
139 7
        $this->enableForceVariation = $enableForceVariation;
140 7
    }
141
    
142 2
    public function getExcludeDisabledExperiments()
143
    {
144 2
        return $this->excludeDisabledExperiments;
145
    }
146
    
147 7
    public function setExcludeDisabledExperiments($excludeDisabledExperiments)
148
    {
149 7
        $this->excludeDisabledExperiments = $excludeDisabledExperiments;
150 7
    }
151
    
152 1
    public function getExcludeNames()
153
    {
154 1
        return $this->excludeNames;
155
    }
156
    
157 7
    public function setExcludeNames($excludeNames)
158
    {
159 7
        $this->excludeNames = $excludeNames;
160 7
    }
161
    
162 1
    public function getIncludeJquery()
163
    {
164 1
        return $this->includeJquery;
165
    }
166
    
167 7
    public function setIncludeJquery($includeJquery)
168
    {
169 7
        $this->includeJquery = $includeJquery;
170 7
    }
171
        
172 1
    public function getIpAnonymization()
173
    {
174 1
        return $this->ipAnonymization;
175
    }
176
    
177 7
    public function setIpAnonymization($ipAnonymization)
178
    {
179 7
        $this->ipAnonymization = $ipAnonymization;
180 7
    }
181
        
182 2
    public function getIpFilter()
183
    {
184 2
        return $this->ipFilter;
185
    }
186
    
187 7
    public function setIpFilter($ipFilter)
188
    {
189 7
        $this->ipFilter = $ipFilter;
190 7
    }
191
    
192 1
    public function getLibrary()
193
    {
194 1
        return $this->library;
195
    }
196
    
197 7
    public function setLibrary($library)
198
    {
199 7
        $this->library = $library;
200 7
    }
201
    
202 1
    public function getProjectJavascript()
203
    {
204 1
        return $this->projectJavascript;
205
    }
206
    
207 7
    public function setProjectJavascript($projectJavascript)
208
    {
209 7
        $this->projectJavascript = $projectJavascript;
210 7
    }
211
    
212 1
    public function getCodeRevision()
213
    {
214 1
        return $this->codeRevision;
215
    }
216
    
217 7
    public function setCodeRevision($codeRevision)
218
    {
219 7
        $this->codeRevision = $codeRevision;
220 7
    }
221
    
222 1
    public function getJsFileSize()
223
    {
224 1
        return $this->jsFileSize;
225
    }
226
    
227 7
    public function setJsFileSize($jsFileSize)
228
    {
229 7
        $this->jsFileSize = $jsFileSize;
230 7
    }
231
}
232
233
234
235
236
237
238
239
240