Completed
Push — master ( 5246d9...f37493 )
by James
04:14
created
tests/OptimizelyPHPTest/Service/v2/AudiencesTest.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
         $result = $audiencesService->listAll(1000);
50 50
         $audiences = $result->getPayload();
51 51
         
52
-        $this->assertTrue(count($audiences)==1);
52
+        $this->assertTrue(count($audiences) == 1);
53 53
         $this->assertTrue($audiences[0] instanceOf Audience);
54
-        $this->assertTrue($audiences[0]->getName()=='Spanish speaking San Franciscans');        
54
+        $this->assertTrue($audiences[0]->getName() == 'Spanish speaking San Franciscans');        
55 55
     }
56 56
     
57 57
     /**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         $audience = $result->getPayload();
123 123
         
124 124
         $this->assertTrue($audience instanceOf Audience);
125
-        $this->assertTrue($audience->getName()=='Spanish speaking San Franciscans');        
125
+        $this->assertTrue($audience->getName() == 'Spanish speaking San Franciscans');        
126 126
     }
127 127
     
128 128
     public function testCreate()
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         $createdAudience = $result->getPayload();
183 183
         
184 184
         $this->assertTrue($createdAudience instanceOf Audience);
185
-        $this->assertTrue($createdAudience->getName()=='Spanish speaking San Franciscans');                
185
+        $this->assertTrue($createdAudience->getName() == 'Spanish speaking San Franciscans');                
186 186
     }
187 187
     
188 188
     public function testUpdate()
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         $createdAudience = $result->getPayload();
243 243
         
244 244
         $this->assertTrue($createdAudience instanceOf Audience);
245
-        $this->assertTrue($createdAudience->getName()=='Spanish speaking San Franciscans');                
245
+        $this->assertTrue($createdAudience->getName() == 'Spanish speaking San Franciscans');                
246 246
     }
247 247
 }
248 248
 
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/OptimizelyApiClient.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
      * @param array $authCredentials Auth credentials.
51 51
      * @param string $apiVersion Optional. Currently supported 'v2' only.     
52 52
      */
53
-    public function __construct($authCredentials, $apiVersion='v2')
53
+    public function __construct($authCredentials, $apiVersion = 'v2')
54 54
     {
55 55
         if (!is_array($authCredentials)) {
56 56
             throw new Exception('Auth credentials must be an array');            
57 57
         }
58 58
         
59
-        if ($apiVersion!='v2') {
59
+        if ($apiVersion != 'v2') {
60 60
             throw new Exception('Invalid API version passed');
61 61
         }
62 62
         
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public function setApiVersion($apiVersion)
87 87
     {
88
-        if ($apiVersion!='v2') {
88
+        if ($apiVersion != 'v2') {
89 89
             throw new Exception('Invalid API version passed');
90 90
         }
91 91
         
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public function setAuthCredentials($authCredentials)
109 109
     {
110
-        if (!is_array($authCredentials) || count($authCredentials)==0) {
110
+        if (!is_array($authCredentials) || count($authCredentials) == 0) {
111 111
             throw new Exception('Auth credentials must be an non-empty array');            
112 112
         }
113 113
         
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
      * @return array Optimizely response in form of array.
167 167
      * @throws Exception
168 168
      */
169
-    public function sendApiRequest($url, $queryParams = array(), $method='GET', 
169
+    public function sendApiRequest($url, $queryParams = array(), $method = 'GET', 
170 170
             $postData = array())
171 171
     {
172 172
         // If access token has expired, try to get another one with refresh token.
173
-        if ($this->isAccessTokenExpired() && $this->getRefreshToken()!=null) {
173
+        if ($this->isAccessTokenExpired() && $this->getRefreshToken() != null) {
174 174
             $this->getAccessTokenByRefreshToken();
175 175
         }
176 176
         
177 177
         // Produce absolute URL
178
-        $url = 'https://api.optimizely.com/' . $this->apiVersion . $url;
178
+        $url = 'https://api.optimizely.com/'.$this->apiVersion.$url;
179 179
         
180 180
         $result = $this->sendHttpRequest($url, $queryParams, $method, $postData);
181 181
         
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @return array Optimizely response in form of array.
192 192
      * @throws Exception
193 193
      */
194
-    private function sendHttpRequest($url, $queryParams = array(), $method='GET', 
194
+    private function sendHttpRequest($url, $queryParams = array(), $method = 'GET', 
195 195
             $postData = array())
196 196
     {
197 197
         // Reset diagnostics info.
@@ -199,36 +199,36 @@  discard block
 block discarded – undo
199 199
         
200 200
         // Check if CURL is initialized (it should have been initialized in 
201 201
         // constructor).
202
-        if ($this->curlHandle==false) {
202
+        if ($this->curlHandle == false) {
203 203
             throw new Exception('CURL is not initialized', 
204 204
                     Exception::CODE_CURL_ERROR);
205 205
         }
206 206
         
207
-        if ($method!='GET' && $method!='POST' && $method!='PUT' && 
208
-            $method!='PATCH' && $method!='DELETE') {
209
-            throw new Exception('Invalid HTTP method passed: ' . $method);
207
+        if ($method != 'GET' && $method != 'POST' && $method != 'PUT' && 
208
+            $method != 'PATCH' && $method != 'DELETE') {
209
+            throw new Exception('Invalid HTTP method passed: '.$method);
210 210
         }
211 211
         
212 212
         if (!isset($this->authCredentials['access_token'])) {
213
-            throw new Exception('OAuth access token is not set. You should pass ' . 
213
+            throw new Exception('OAuth access token is not set. You should pass '. 
214 214
                     'it to the class constructor when initializing the Optimizely client.');
215 215
         }
216 216
                 
217 217
         // Append query parameters to URL.
218
-        if (count($queryParams)!=0) {            
218
+        if (count($queryParams) != 0) {            
219 219
             $query = http_build_query($queryParams);
220
-            $url .= '?' . $query;
220
+            $url .= '?'.$query;
221 221
         }
222 222
         
223 223
         $headers = array(
224
-            "Authorization: Bearer " . $this->authCredentials['access_token'],
224
+            "Authorization: Bearer ".$this->authCredentials['access_token'],
225 225
             "Content-Type: application/json"
226 226
             );
227 227
         $content = '';
228
-        if (count($postData)!=0) {
228
+        if (count($postData) != 0) {
229 229
             $content = json_encode($postData);            
230 230
         }
231
-        $headers[] = "Content-length:" . strlen($content);            
231
+        $headers[] = "Content-length:".strlen($content);            
232 232
         
233 233
         // Reset CURL state.
234 234
         if (!function_exists('curl_reset')) {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         // Set HTTP options.
242 242
         curl_setopt($this->curlHandle, CURLOPT_URL, $url);
243 243
         curl_setopt($this->curlHandle, CURLOPT_CUSTOMREQUEST, $method);        
244
-        if (count($postData)!=0) {
244
+        if (count($postData) != 0) {
245 245
             curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, $content);            
246 246
         }
247 247
         curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true);
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
         if ($result === false) {
261 261
             $code = curl_errno($this->curlHandle);
262 262
             $error = curl_error($this->curlHandle);
263
-            throw new Exception("Failed to send HTTP request $method '$url', " . 
263
+            throw new Exception("Failed to send HTTP request $method '$url', ". 
264 264
                     "the error code was $code, error message was: '$error'", 
265 265
                     Exception::CODE_CURL_ERROR, $code, $error);
266 266
         }        
@@ -274,12 +274,12 @@  discard block
 block discarded – undo
274 274
         $headers = explode("\n", $headers);
275 275
         $parsedHeaders = array();
276 276
         foreach ($headers as $i=>$header) {
277
-            if ($i==0)
277
+            if ($i == 0)
278 278
                 continue; // Skip first line (http code).
279 279
             $pos = strpos($header, ':');
280
-            if ($pos!=false) {
280
+            if ($pos != false) {
281 281
                 $headerName = trim(strtolower(substr($header, 0, $pos)));
282
-                $headerValue = trim(substr($header, $pos+1));
282
+                $headerValue = trim(substr($header, $pos + 1));
283 283
                 $parsedHeaders[$headerName] = $headerValue;
284 284
             }
285 285
         }
@@ -311,20 +311,20 @@  discard block
 block discarded – undo
311 311
         
312 312
         // JSON-decode payload.
313 313
         $decodedPayload = json_decode($body, true);
314
-        if ($decodedPayload===false) {
315
-            throw new Exception('Could not JSON-decode the Optimizely API response. Request was ' . 
316
-                    $method . ' "' . $url . '". The response was: "' . $body . '"',
314
+        if ($decodedPayload === false) {
315
+            throw new Exception('Could not JSON-decode the Optimizely API response. Request was '. 
316
+                    $method.' "'.$url.'". The response was: "'.$body.'"',
317 317
                     Exception::CODE_API_ERROR, array('http_code'=>$httpCode));
318 318
         }
319 319
         
320 320
         // Check HTTP response code.
321
-        if ($httpCode<200 || $httpCode>299) {
321
+        if ($httpCode < 200 || $httpCode > 299) {
322 322
             
323 323
             if (!isset($decodedPayload['message']) || 
324 324
                 !isset($decodedPayload['code']) ||
325 325
                 !isset($decodedPayload['uuid'])) {
326
-                throw new Exception('Optimizely API responded with error code ' . $httpCode . 
327
-                    '. Request was ' . $method . ' "' . $url . '". Response was "' . $body . '"',
326
+                throw new Exception('Optimizely API responded with error code '.$httpCode. 
327
+                    '. Request was '.$method.' "'.$url.'". Response was "'.$body.'"',
328 328
                     Exception::CODE_API_ERROR, array(
329 329
                         'http_code' => $httpCode,
330 330
                         'rate_limit' => $rateLimit,
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
             $matched = preg_match_all('/<(.+)>;\s+rel=(\w+)(,|\z)/U', 
357 357
                     $parsedHeaders['link'], $matches, PREG_SET_ORDER);
358 358
             if (!$matched) {
359
-                throw new Exception('Error parsing LINK header: ' . 
359
+                throw new Exception('Error parsing LINK header: '. 
360 360
                         $parsedHeaders['link'], Exception::CODE_API_ERROR, $httpCode);
361 361
             }
362 362
             
@@ -366,22 +366,22 @@  discard block
 block discarded – undo
366 366
                 $rel = $match[2];
367 367
                 
368 368
                 $matched = preg_match('/page=(\d+)/U', $url, $pageMatches);
369
-                if (!$matched || count($pageMatches)!=2) {
370
-                    throw new Exception('Error extracting page argument while parsing LINK header: ' . 
369
+                if (!$matched || count($pageMatches) != 2) {
370
+                    throw new Exception('Error extracting page argument while parsing LINK header: '. 
371 371
                             $parsedHeaders['link'], Exception::CODE_API_ERROR, 
372 372
                             array('http_code'=>$httpCode));
373 373
                 }
374 374
                 
375 375
                 $pageNumber = $pageMatches[1];
376 376
                 
377
-                if ($rel=='prev') {
377
+                if ($rel == 'prev') {
378 378
                     $result->setPrevPage($pageNumber);
379
-                } else if ($rel=='next') {
379
+                } else if ($rel == 'next') {
380 380
                     $result->setNextPage($pageNumber);
381
-                } else if ($rel=='last') {
381
+                } else if ($rel == 'last') {
382 382
                     $result->setLastPage($pageNumber);
383 383
                 } else {
384
-                    throw new Exception('Unexpected rel argument while parsing LINK header: ' . 
384
+                    throw new Exception('Unexpected rel argument while parsing LINK header: '. 
385 385
                             $parsedHeaders['link'], Exception::CODE_API_ERROR, 
386 386
                             array('http_code'=>$httpCode));
387 387
                 }
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
      */
400 400
     private function isAccessTokenExpired() 
401 401
     {
402
-        if(!isset($this->authCredentials['access_token'])) {
402
+        if (!isset($this->authCredentials['access_token'])) {
403 403
             return true; // We do not have access token.
404 404
         }
405 405
         
@@ -440,15 +440,15 @@  discard block
 block discarded – undo
440 440
         $clientSecret = $this->authCredentials['client_secret'];
441 441
         $refreshToken = $this->authCredentials['refresh_token'];
442 442
         
443
-        $url = "https://app.optimizely.com/oauth2/token?refresh_token=$refreshToken" . 
443
+        $url = "https://app.optimizely.com/oauth2/token?refresh_token=$refreshToken". 
444 444
                 "&client_id=$clientId&client_secret=$clientSecret&grant_type=refresh_token";
445 445
         
446 446
         $response = $this->sendHttpRequest($url, array(), 'POST');
447 447
         $decodedJsonData = $response->getDecodedJsonData();
448 448
         
449 449
         if (!isset($decodedJsonData['access_token'])) {
450
-            throw new Exception('Not found access token in response. Request URL was "' . 
451
-                    $url. '". Response was "' . print_r(json_encode($decodedJsonData), true). '"',
450
+            throw new Exception('Not found access token in response. Request URL was "'. 
451
+                    $url.'". Response was "'.print_r(json_encode($decodedJsonData), true).'"',
452 452
                     Exception::CODE_API_ERROR, $response->getHttpCode());
453 453
         }
454 454
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Projects.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,13 +35,13 @@  discard block
 block discarded – undo
35 35
      * @return Result
36 36
      * @throws Exception
37 37
      */
38
-    public function listAll($page=1, $perPage=25)
38
+    public function listAll($page = 1, $perPage = 25)
39 39
     {
40
-        if ($page<0) {
40
+        if ($page < 0) {
41 41
             throw new Exception('Invalid page number passed');
42 42
         }
43 43
         
44
-        if ($perPage<0 || $perPage>100) {
44
+        if ($perPage < 0 || $perPage > 100) {
45 45
             throw new Exception('Invalid page size passed');
46 46
         }
47 47
         
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function get($projectId)
71 71
     {
72
-        $projectId = (string)$projectId;
72
+        $projectId = (string) $projectId;
73 73
         
74 74
         if (!preg_match('/^\d+$/', $projectId)) {
75 75
             throw new Exception("A positive integer project ID expected, while got $projectId");
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function update($projectId, $project) 
116 116
     {
117
-        $projectId = (string)$projectId;
117
+        $projectId = (string) $projectId;
118 118
         
119 119
         if (!preg_match('/\d+/', $projectId)) {
120 120
             throw new Exception("A positive integer project ID expected, while got $projectId");
121 121
         }
122 122
         
123
-        if ($projectId<0) {
123
+        if ($projectId < 0) {
124 124
             throw new Exception("A positive project ID expected");
125 125
         }
126 126
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Resource/v2/Event.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@
 block discarded – undo
91 91
         // Remove options with empty values
92 92
         $cleanedOptions = array();
93 93
         foreach ($options as $name=>$value) {
94
-            if ($value!==null)
95
-                $cleanedOptions[$name] = $value;
94
+            if ($value!==null) {
95
+                            $cleanedOptions[$name] = $value;
96
+            }
96 97
         }
97 98
         
98 99
         return $cleanedOptions;
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Resource/v2/VariantResults.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@
 block discarded – undo
91 91
         // Remove options with empty values
92 92
         $cleanedOptions = array();
93 93
         foreach ($options as $name=>$value) {
94
-            if ($value!==null)
95
-                $cleanedOptions[$name] = $value;
94
+            if ($value!==null) {
95
+                            $cleanedOptions[$name] = $value;
96
+            }
96 97
         }
97 98
         
98 99
         return $cleanedOptions;
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Resource/v2/VariationReach.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@
 block discarded – undo
91 91
         // Remove options with empty values
92 92
         $cleanedOptions = array();
93 93
         foreach ($options as $name=>$value) {
94
-            if ($value!==null)
95
-                $cleanedOptions[$name] = $value;
94
+            if ($value!==null) {
95
+                            $cleanedOptions[$name] = $value;
96
+            }
96 97
         }
97 98
         
98 99
         return $cleanedOptions;
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Resource/v2/Project.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
                 case 'last_modified': $this->setLastModified($value); break;
123 123
                 case 'socket_token': $this->setSocketToken($value); break;
124 124
                 default:
125
-                    throw new Exception('Unknown option: ' . $name);
125
+                    throw new Exception('Unknown option: '.$name);
126 126
             }
127 127
         }
128 128
     }
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
             'platform' => $this->getPlatform(),
141 141
             'sdks' => $this->getSdks(),
142 142
             'status' => $this->getStatus(),
143
-            'web_snippet' => $this->getWebSnippet()?$this->getWebSnippet()->toArray():null,
143
+            'web_snippet' => $this->getWebSnippet() ? $this->getWebSnippet()->toArray() : null,
144 144
             'created' => $this->getCreated(),
145 145
             'id' => $this->getId(),
146 146
             'is_classic' => $this->getIsClassic(),
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         // Remove options with empty values
152 152
         $cleanedOptions = array();
153 153
         foreach ($options as $name=>$value) {
154
-            if ($value!==null)
154
+            if ($value !== null)
155 155
                 $cleanedOptions[$name] = $value;
156 156
         }
157 157
         
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@
 block discarded – undo
91 91
         // Remove options with empty values
92 92
         $cleanedOptions = array();
93 93
         foreach ($options as $name=>$value) {
94
-            if ($value!==null)
95
-                $cleanedOptions[$name] = $value;
94
+            if ($value!==null) {
95
+                            $cleanedOptions[$name] = $value;
96
+            }
96 97
         }
97 98
         
98 99
         return $cleanedOptions;
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Resource/v2/ExperimentResults.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@
 block discarded – undo
91 91
         // Remove options with empty values
92 92
         $cleanedOptions = array();
93 93
         foreach ($options as $name=>$value) {
94
-            if ($value!==null)
95
-                $cleanedOptions[$name] = $value;
94
+            if ($value!==null) {
95
+                            $cleanedOptions[$name] = $value;
96
+            }
96 97
         }
97 98
         
98 99
         return $cleanedOptions;
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Resource/v2/Experiment.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@
 block discarded – undo
91 91
         // Remove options with empty values
92 92
         $cleanedOptions = array();
93 93
         foreach ($options as $name=>$value) {
94
-            if ($value!==null)
95
-                $cleanedOptions[$name] = $value;
94
+            if ($value!==null) {
95
+                            $cleanedOptions[$name] = $value;
96
+            }
96 97
         }
97 98
         
98 99
         return $cleanedOptions;
Please login to merge, or discard this patch.