Completed
Push — master ( 8b4718...61d59f )
by Oleg
02:27
created
tests/OptimizelyPHPTest/Service/v2/ProjectsTest.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
         $result = $projectsService->listAll();
52 52
         $projects = $result->getPayload();
53 53
         
54
-        $this->assertTrue(count($projects)==1);
54
+        $this->assertTrue(count($projects) == 1);
55 55
         $this->assertTrue($projects[0] instanceOf Project);
56
-        $this->assertTrue($projects[0]->getName()=='Some Optimizely Project');        
56
+        $this->assertTrue($projects[0]->getName() == 'Some Optimizely Project');        
57 57
     }
58 58
     
59 59
     /**
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         $project = $result->getPayload();
127 127
         
128 128
         $this->assertTrue($project instanceOf Project);
129
-        $this->assertTrue($project->getName()=='Some Optimizely Project');        
129
+        $this->assertTrue($project->getName() == 'Some Optimizely Project');        
130 130
     }
131 131
     
132 132
     /**
@@ -221,8 +221,8 @@  discard block
 block discarded – undo
221 221
         $createdProject = $result->getPayload();
222 222
         
223 223
         $this->assertTrue($createdProject instanceOf Project);
224
-        $this->assertTrue($createdProject->getName()=='Test Project');        
225
-        $this->assertTrue($createdProject->getAccountId()==12345);        
224
+        $this->assertTrue($createdProject->getName() == 'Test Project');        
225
+        $this->assertTrue($createdProject->getAccountId() == 12345);        
226 226
     }
227 227
     
228 228
     /**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
         $updatedProject = $result->getPayload();
302 302
         
303 303
         $this->assertTrue($updatedProject instanceOf Project);
304
-        $this->assertTrue($updatedProject->getName()=='Test Project');        
305
-        $this->assertTrue($updatedProject->getAccountId()==12345);        
304
+        $this->assertTrue($updatedProject->getName() == 'Test Project');        
305
+        $this->assertTrue($updatedProject->getAccountId() == 12345);        
306 306
     }
307 307
     
308 308
     /**
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
         $credentials = $this->loadCredentialsFromFile();
363 363
         
364 364
         $optimizelyClient = new OptimizelyApiClient($credentials, 'v2');
365
-        $this->assertTrue($optimizelyClient!=null);
365
+        $this->assertTrue($optimizelyClient != null);
366 366
         
367 367
         $curDate = date('Y-m-d H:i:s');
368 368
         /*// Create new project        
@@ -408,17 +408,17 @@  discard block
 block discarded – undo
408 408
                 $projects = $result->getPayload();
409 409
 
410 410
                 foreach ($projects as $project) {
411
-                    if ($project->getName()=="Test Project $curDate") {
411
+                    if ($project->getName() == "Test Project $curDate") {
412 412
                         $projectId = $project->getId();
413 413
                         $found = true;
414 414
                         break;
415 415
                     }
416 416
                 }
417 417
 
418
-                if ($result->getNextPage()==null)
418
+                if ($result->getNextPage() == null)
419 419
                     break;
420 420
 
421
-                $page ++;
421
+                $page++;
422 422
             }
423 423
         }
424 424
         catch (Exception $e) {
@@ -437,13 +437,13 @@  discard block
 block discarded – undo
437 437
         try {
438 438
             $result = $optimizelyClient->projects()->get(12345678);        
439 439
         } 
440
-        catch(Exception $e) {
440
+        catch (Exception $e) {
441 441
             $this->assertEquals(Exception::CODE_API_ERROR, $e->getCode());
442 442
             $this->assertEquals(400, $e->getHttpCode());
443
-            $this->assertTrue(strlen($e->getUuid())!=0);
444
-            $this->assertTrue($e->getRateLimit()>0);
445
-            $this->assertTrue($e->getRateLimitRemaining()>0);
446
-            $this->assertTrue($e->getRateLimitReset()>0);
443
+            $this->assertTrue(strlen($e->getUuid()) != 0);
444
+            $this->assertTrue($e->getRateLimit() > 0);
445
+            $this->assertTrue($e->getRateLimitRemaining() > 0);
446
+            $this->assertTrue($e->getRateLimitReset() > 0);
447 447
         }
448 448
         
449 449
         // Retrieve existing project by ID        
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,41 +199,41 @@  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
         // Set HTTP options.
234 234
         curl_setopt($this->curlHandle, CURLOPT_URL, $url);
235 235
         curl_setopt($this->curlHandle, CURLOPT_CUSTOMREQUEST, $method);        
236
-        if (count($postData)!=0) {
236
+        if (count($postData) != 0) {
237 237
             curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, $content);            
238 238
         }
239 239
         curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true);
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
         if ($result === false) {
253 253
             $code = curl_errno($this->curlHandle);
254 254
             $error = curl_error($this->curlHandle);
255
-            throw new Exception("Failed to send HTTP request $method '$url', " . 
255
+            throw new Exception("Failed to send HTTP request $method '$url', ". 
256 256
                     "the error code was $code, error message was: '$error'", 
257 257
                     Exception::CODE_CURL_ERROR, $code, $error);
258 258
         }        
@@ -266,12 +266,12 @@  discard block
 block discarded – undo
266 266
         $headers = explode("\n", $headers);
267 267
         $parsedHeaders = array();
268 268
         foreach ($headers as $i=>$header) {
269
-            if ($i==0)
269
+            if ($i == 0)
270 270
                 continue; // Skip first line (http code).
271 271
             $pos = strpos($header, ':');
272
-            if ($pos!=false) {
272
+            if ($pos != false) {
273 273
                 $headerName = trim(strtolower(substr($header, 0, $pos)));
274
-                $headerValue = trim(substr($header, $pos+1));
274
+                $headerValue = trim(substr($header, $pos + 1));
275 275
                 $parsedHeaders[$headerName] = $headerValue;
276 276
             }
277 277
         }
@@ -303,21 +303,21 @@  discard block
 block discarded – undo
303 303
         
304 304
         // JSON-decode payload.
305 305
         $decodedPayload = json_decode($body, true);
306
-        if ($decodedPayload===false) {
307
-            throw new Exception('Could not JSON-decode the Optimizely API response. Request was ' . 
308
-                    $method . ' "' . $url . '". The response was: "' . $body . '"',
306
+        if ($decodedPayload === false) {
307
+            throw new Exception('Could not JSON-decode the Optimizely API response. Request was '. 
308
+                    $method.' "'.$url.'". The response was: "'.$body.'"',
309 309
                     Exception::CODE_API_ERROR, array('http_code'=>$httpCode));
310 310
         }
311 311
         
312 312
         // Check HTTP response code.
313
-        if ($httpCode<200 || $httpCode>299) {
313
+        if ($httpCode < 200 || $httpCode > 299) {
314 314
             
315 315
             if (!isset($decodedPayload['message']) || 
316 316
                 !isset($decodedPayload['code']) ||
317 317
                 !isset($decodedPayload['uuid']) ||
318 318
                 $httpCode != !isset($decodedPayload['code'])) {
319
-                throw new Exception('Optimizely API responded with error code ' . $httpCode . 
320
-                    '. Request was ' . $method . ' "' . $url . '". Response was "' . $body . '"',
319
+                throw new Exception('Optimizely API responded with error code '.$httpCode. 
320
+                    '. Request was '.$method.' "'.$url.'". Response was "'.$body.'"',
321 321
                     Exception::CODE_API_ERROR, array(
322 322
                         'http_code' => $httpCode,
323 323
                         'rate_limit' => $rateLimit,
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
             $matched = preg_match_all('/<(.+)>;\s+rel=(\w+)(,|\z)/U', 
350 350
                     $parsedHeaders['link'], $matches, PREG_SET_ORDER);
351 351
             if (!$matched) {
352
-                throw new Exception('Error parsing LINK header: ' . 
352
+                throw new Exception('Error parsing LINK header: '. 
353 353
                         $parsedHeaders['link'], Exception::CODE_API_ERROR, $httpCode);
354 354
             }
355 355
             
@@ -359,22 +359,22 @@  discard block
 block discarded – undo
359 359
                 $rel = $match[2];
360 360
                 
361 361
                 $matched = preg_match('/page=(\d+)/U', $url, $pageMatches);
362
-                if (!$matched || count($pageMatches)!=2) {
363
-                    throw new Exception('Error extracting page argument while parsing LINK header: ' . 
362
+                if (!$matched || count($pageMatches) != 2) {
363
+                    throw new Exception('Error extracting page argument while parsing LINK header: '. 
364 364
                             $parsedHeaders['link'], Exception::CODE_API_ERROR, 
365 365
                             array('http_code'=>$httpCode));
366 366
                 }
367 367
                 
368 368
                 $pageNumber = $pageMatches[1];
369 369
                 
370
-                if ($rel=='prev') {
370
+                if ($rel == 'prev') {
371 371
                     $result->setPrevPage($pageNumber);
372
-                } else if ($rel=='next') {
372
+                } else if ($rel == 'next') {
373 373
                     $result->setNextPage($pageNumber);
374
-                } else if ($rel=='last') {
374
+                } else if ($rel == 'last') {
375 375
                     $result->setLastPage($pageNumber);
376 376
                 } else {
377
-                    throw new Exception('Unexpected rel argument while parsing LINK header: ' . 
377
+                    throw new Exception('Unexpected rel argument while parsing LINK header: '. 
378 378
                             $parsedHeaders['link'], Exception::CODE_API_ERROR, 
379 379
                             array('http_code'=>$httpCode));
380 380
                 }
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
      */
393 393
     private function isAccessTokenExpired() 
394 394
     {
395
-        if(!isset($this->authCredentials['access_token'])) {
395
+        if (!isset($this->authCredentials['access_token'])) {
396 396
             return true; // We do not have access token.
397 397
         }
398 398
         
@@ -433,15 +433,15 @@  discard block
 block discarded – undo
433 433
         $clientSecret = $this->authCredentials['client_secret'];
434 434
         $refreshToken = $this->authCredentials['refresh_token'];
435 435
         
436
-        $url = "https://app.optimizely.com/oauth2/token?refresh_token=$refreshToken" . 
436
+        $url = "https://app.optimizely.com/oauth2/token?refresh_token=$refreshToken". 
437 437
                 "&client_id=$clientId&client_secret=$clientSecret&grant_type=refresh_token";
438 438
         
439 439
         $response = $this->sendHttpRequest($url, array(), 'POST');
440 440
         $decodedJsonData = $response->getDecodedJsonData();
441 441
         
442 442
         if (!isset($decodedJsonData['access_token'])) {
443
-            throw new Exception('Not found access token in response. Request URL was "' . 
444
-                    $url. '". Response was "' . print_r(json_encode($decodedJsonData), true). '"',
443
+            throw new Exception('Not found access token in response. Request URL was "'. 
444
+                    $url.'". Response was "'.print_r(json_encode($decodedJsonData), true).'"',
445 445
                     Exception::CODE_API_ERROR, $response->getHttpCode());
446 446
         }
447 447
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Campaigns.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
      * @return Result
38 38
      * @throws Exception
39 39
      */
40
-    public function listAll($projectId, $page=1, $perPage=25)
40
+    public function listAll($projectId, $page = 1, $perPage = 25)
41 41
     {
42 42
         if (!is_int($projectId)) {
43 43
             throw new Exception("Integer project ID expected, while got '$projectId'");
44 44
         }
45 45
         
46
-        if ($projectId<0) {
46
+        if ($projectId < 0) {
47 47
             throw new Exception("Expected positive integer project ID");
48 48
         }
49 49
         
50
-        if ($page<0) {
50
+        if ($page < 0) {
51 51
             throw new Exception('Invalid page number passed');
52 52
         }
53 53
         
54
-        if ($perPage<0 || $perPage>100) {
54
+        if ($perPage < 0 || $perPage > 100) {
55 55
             throw new Exception('Invalid page size passed');
56 56
         }
57 57
         
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                     Exception::CODE_INVALID_ARG);
108 108
         }
109 109
         
110
-        if ($campaignId<0) {
110
+        if ($campaignId < 0) {
111 111
             throw new Exception("Expected positive integer campaign ID",
112 112
                     Exception::CODE_INVALID_ARG);
113 113
         }
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Audiences.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,13 +36,13 @@
 block discarded – undo
36 36
      * @return Result
37 37
      * @throws Exception
38 38
      */
39
-    public function listAll($projectId, $page=1, $perPage=25)
39
+    public function listAll($projectId, $page = 1, $perPage = 25)
40 40
     {
41
-        if ($page<0) {
41
+        if ($page < 0) {
42 42
             throw new Exception('Invalid page number passed');
43 43
         }
44 44
         
45
-        if ($perPage<0 || $perPage>100) {
45
+        if ($perPage < 0 || $perPage > 100) {
46 46
             throw new Exception('Invalid page size passed');
47 47
         }
48 48
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Experiments.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,17 +39,17 @@  discard block
 block discarded – undo
39 39
      * @return Result
40 40
      * @throws Exception
41 41
      */
42
-    public function listAll($projectId, $campaignId=null, $includeClassic=false, $page=1, $perPage=25)
42
+    public function listAll($projectId, $campaignId = null, $includeClassic = false, $page = 1, $perPage = 25)
43 43
     {
44
-        if ($projectId==null && $campaignId==null) {
44
+        if ($projectId == null && $campaignId == null) {
45 45
             throw new Exception('Project ID or Campaign ID must be non-null');
46 46
         }
47 47
         
48
-        if ($page<0) {
48
+        if ($page < 0) {
49 49
             throw new Exception('Invalid page number passed');
50 50
         }
51 51
         
52
-        if ($perPage<0 || $perPage>100) {
52
+        if ($perPage < 0 || $perPage > 100) {
53 53
             throw new Exception('Invalid page size passed');
54 54
         }
55 55
         
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
                     Exception::CODE_INVALID_ARG);
86 86
         }
87 87
         
88
-        if ($experimentId<0) {
88
+        if ($experimentId < 0) {
89 89
             throw new Exception("A positive experiment ID expected");
90 90
         }
91 91
         
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             throw new Exception("Expected argument of type Experiment");
176 176
         }
177 177
         
178
-        if ($experimentId<0) {
178
+        if ($experimentId < 0) {
179 179
             throw new Exception("Expected positive experiment ID argument");
180 180
         }
181 181
         
Please login to merge, or discard this patch.
examples/Projects/CreateProject.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 use WebMarketingROI\OptimizelyPHP\Resource\v2\Project;
18 18
 
19 19
 // Init class autloading.
20
-include dirname(__FILE__) . '/../../vendor/autoload.php';
20
+include dirname(__FILE__).'/../../vendor/autoload.php';
21 21
 
22 22
 // Include Utils.php - a file containing helper functions
23
-include dirname(__FILE__) . '/../Utils.php';
23
+include dirname(__FILE__).'/../Utils.php';
24 24
 
25 25
 // Get OAuth 2.0 credentials from auth_credentials.json and access_token.json files.
26 26
 $credentials = load_credentials_from_file();
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
                 echo "Project: $name\n";
61 61
             }
62 62
 
63
-            if ($result->getNextPage()==null)
63
+            if ($result->getNextPage() == null)
64 64
                 break;
65 65
 
66
-            $page ++;
66
+            $page++;
67 67
         }
68 68
     }
69 69
     catch (Exception $e) {
@@ -87,6 +87,6 @@  discard block
 block discarded – undo
87 87
 
88 88
 // Save access token for later use
89 89
 $accessToken = $optimizelyClient->getAccessToken();
90
-file_put_contents(dirname(__FILE__) . '/../access_token.json', json_encode($accessToken));
90
+file_put_contents(dirname(__FILE__).'/../access_token.json', json_encode($accessToken));
91 91
 
92 92
 echo "Done!\n";
93 93
\ No newline at end of file
Please login to merge, or discard this patch.