@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | $result = $pagesService->listAll(1000); |
43 | 43 | $pages = $result->getPayload(); |
44 | 44 | |
45 | - $this->assertTrue(count($pages)==1); |
|
45 | + $this->assertTrue(count($pages) == 1); |
|
46 | 46 | $this->assertTrue($pages[0] instanceOf Page); |
47 | - $this->assertTrue($pages[0]->getName()=='Home Page'); |
|
47 | + $this->assertTrue($pages[0]->getName() == 'Home Page'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | public function testGet() |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $createdPage = $result->getPayload(); |
128 | 128 | |
129 | 129 | $this->assertTrue($createdPage instanceOf Page); |
130 | - $this->assertTrue($createdPage->getName()=='Home Page'); |
|
130 | + $this->assertTrue($createdPage->getName() == 'Home Page'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | public function testUpdate() |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $updatedPage = $result->getPayload(); |
176 | 176 | |
177 | 177 | $this->assertTrue($updatedPage instanceOf Page); |
178 | - $this->assertTrue($updatedPage->getName()=='Home Page'); |
|
178 | + $this->assertTrue($updatedPage->getName() == 'Home Page'); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | public function testDelete() |
@@ -49,9 +49,9 @@ discard block |
||
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 | public function testGet() |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $audience = $result->getPayload(); |
93 | 93 | |
94 | 94 | $this->assertTrue($audience instanceOf Audience); |
95 | - $this->assertTrue($audience->getName()=='Spanish speaking San Franciscans'); |
|
95 | + $this->assertTrue($audience->getName() == 'Spanish speaking San Franciscans'); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | public function testCreate() |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $createdAudience = $result->getPayload(); |
153 | 153 | |
154 | 154 | $this->assertTrue($createdAudience instanceOf Audience); |
155 | - $this->assertTrue($createdAudience->getName()=='Spanish speaking San Franciscans'); |
|
155 | + $this->assertTrue($createdAudience->getName() == 'Spanish speaking San Franciscans'); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | public function testUpdate() |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $createdAudience = $result->getPayload(); |
213 | 213 | |
214 | 214 | $this->assertTrue($createdAudience instanceOf Audience); |
215 | - $this->assertTrue($createdAudience->getName()=='Spanish speaking San Franciscans'); |
|
215 | + $this->assertTrue($createdAudience->getName() == 'Spanish speaking San Franciscans'); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | $result = $projectsService->listAll(); |
51 | 51 | $projects = $result->getPayload(); |
52 | 52 | |
53 | - $this->assertTrue(count($projects)==1); |
|
53 | + $this->assertTrue(count($projects) == 1); |
|
54 | 54 | $this->assertTrue($projects[0] instanceOf Project); |
55 | - $this->assertTrue($projects[0]->getName()=='Some Optimizely Project'); |
|
55 | + $this->assertTrue($projects[0]->getName() == 'Some Optimizely Project'); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | public function testGet() |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $project = $result->getPayload(); |
96 | 96 | |
97 | 97 | $this->assertTrue($project instanceOf Project); |
98 | - $this->assertTrue($project->getName()=='Some Optimizely Project'); |
|
98 | + $this->assertTrue($project->getName() == 'Some Optimizely Project'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | public function testCreate() |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | $createdProject = $result->getPayload(); |
161 | 161 | |
162 | 162 | $this->assertTrue($createdProject instanceOf Project); |
163 | - $this->assertTrue($createdProject->getName()=='Test Project'); |
|
164 | - $this->assertTrue($createdProject->getAccountId()==12345); |
|
163 | + $this->assertTrue($createdProject->getName() == 'Test Project'); |
|
164 | + $this->assertTrue($createdProject->getAccountId() == 12345); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | public function testUpdate() |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | $updatedProject = $result->getPayload(); |
226 | 226 | |
227 | 227 | $this->assertTrue($updatedProject instanceOf Project); |
228 | - $this->assertTrue($updatedProject->getName()=='Test Project'); |
|
229 | - $this->assertTrue($updatedProject->getAccountId()==12345); |
|
228 | + $this->assertTrue($updatedProject->getName() == 'Test Project'); |
|
229 | + $this->assertTrue($updatedProject->getAccountId() == 12345); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | public function testIntegration() |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $credentials = $this->loadCredentialsFromFile(); |
238 | 238 | |
239 | 239 | $optimizelyClient = new OptimizelyApiClient($credentials, 'v2'); |
240 | - $this->assertTrue($optimizelyClient!=null); |
|
240 | + $this->assertTrue($optimizelyClient != null); |
|
241 | 241 | |
242 | 242 | // Create new project |
243 | 243 | $curDate = date('Y-m-d H:i:s'); |
@@ -277,17 +277,17 @@ discard block |
||
277 | 277 | $projects = $result->getPayload(); |
278 | 278 | |
279 | 279 | foreach ($projects as $project) { |
280 | - if ($project->getName()=="Test Project $curDate") { |
|
280 | + if ($project->getName() == "Test Project $curDate") { |
|
281 | 281 | $projectId = $project->getId(); |
282 | 282 | $found = true; |
283 | 283 | break; |
284 | 284 | } |
285 | 285 | } |
286 | 286 | |
287 | - if ($result->getNextPage()==null) |
|
287 | + if ($result->getNextPage() == null) |
|
288 | 288 | break; |
289 | 289 | |
290 | - $page ++; |
|
290 | + $page++; |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | $this->assertTrue($projectFound); |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | use WebMarketingROI\OptimizelyPHP\Exception; |
17 | 17 | |
18 | 18 | // Init class autloading. |
19 | -include dirname(__FILE__) . '/../../vendor/autoload.php'; |
|
19 | +include dirname(__FILE__).'/../../vendor/autoload.php'; |
|
20 | 20 | |
21 | 21 | // Include Utils.php - a file containing helper functions |
22 | -include dirname(__FILE__) . '/../Utils.php'; |
|
22 | +include dirname(__FILE__).'/../Utils.php'; |
|
23 | 23 | |
24 | 24 | // Get OAuth 2.0 credentials from auth_credentials.json and access_token.json files. |
25 | 25 | $credentials = load_credentials_from_file(); |
@@ -42,24 +42,24 @@ discard block |
||
42 | 42 | $projects = $result->getPayload(); |
43 | 43 | |
44 | 44 | foreach ($projects as $project) { |
45 | - echo "ID: " . $project->getId() . "\n"; |
|
46 | - echo "Name: " . $project->getName() . "\n"; |
|
47 | - echo "Account ID: " . $project->getAccountId() . "\n"; |
|
48 | - echo "Platform: " . $project->getPlatform() . "\n"; |
|
49 | - echo "Status: " . $project->getStatus() . "\n"; |
|
50 | - echo "Is Classic: " . ($project->getIsClassic()?"true":"false") . "\n"; |
|
51 | - echo "Created: " . $project->getCreated() . "\n"; |
|
52 | - echo "Last Modified: " . $project->getLastModified() . "\n"; |
|
45 | + echo "ID: ".$project->getId()."\n"; |
|
46 | + echo "Name: ".$project->getName()."\n"; |
|
47 | + echo "Account ID: ".$project->getAccountId()."\n"; |
|
48 | + echo "Platform: ".$project->getPlatform()."\n"; |
|
49 | + echo "Status: ".$project->getStatus()."\n"; |
|
50 | + echo "Is Classic: ".($project->getIsClassic() ? "true" : "false")."\n"; |
|
51 | + echo "Created: ".$project->getCreated()."\n"; |
|
52 | + echo "Last Modified: ".$project->getLastModified()."\n"; |
|
53 | 53 | |
54 | 54 | echo "\n"; |
55 | 55 | } |
56 | 56 | |
57 | 57 | // Determine if there are more projects. |
58 | - if ($result->getNextPage()==null) |
|
58 | + if ($result->getNextPage() == null) |
|
59 | 59 | break; |
60 | 60 | |
61 | 61 | // Increment page counter. |
62 | - $page ++; |
|
62 | + $page++; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | } catch (Exception $e) { |
@@ -73,6 +73,6 @@ discard block |
||
73 | 73 | |
74 | 74 | // Save access token for later use |
75 | 75 | $accessToken = $optimizelyClient->getAccessToken(); |
76 | -file_put_contents(dirname(__FILE__) . '/../access_token.json', json_encode($accessToken)); |
|
76 | +file_put_contents(dirname(__FILE__).'/../access_token.json', json_encode($accessToken)); |
|
77 | 77 | |
78 | 78 | echo "Done!\n"; |
79 | 79 | \ No newline at end of file |
@@ -17,14 +17,14 @@ discard block |
||
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 | // Read project ID from command line. |
26 | -if ($argc!=2) { |
|
27 | - die('Expected 1 command-line argument, while got ' . $argc-1); |
|
26 | +if ($argc != 2) { |
|
27 | + die('Expected 1 command-line argument, while got '.$argc - 1); |
|
28 | 28 | } |
29 | 29 | $projectId = $argv[1]; |
30 | 30 | |
@@ -56,6 +56,6 @@ discard block |
||
56 | 56 | |
57 | 57 | // Save access token for later use |
58 | 58 | $accessToken = $optimizelyClient->getAccessToken(); |
59 | -file_put_contents(dirname(__FILE__) . '/../access_token.json', json_encode($accessToken)); |
|
59 | +file_put_contents(dirname(__FILE__).'/../access_token.json', json_encode($accessToken)); |
|
60 | 60 | |
61 | 61 | echo "Done!\n"; |
62 | 62 | \ No newline at end of file |
@@ -16,14 +16,14 @@ discard block |
||
16 | 16 | use WebMarketingROI\OptimizelyPHP\Exception; |
17 | 17 | |
18 | 18 | // Init class autloading. |
19 | -include dirname(__FILE__) . '/../../vendor/autoload.php'; |
|
19 | +include dirname(__FILE__).'/../../vendor/autoload.php'; |
|
20 | 20 | |
21 | 21 | // Include Utils.php - a file containing helper functions |
22 | -include dirname(__FILE__) . '/../Utils.php'; |
|
22 | +include dirname(__FILE__).'/../Utils.php'; |
|
23 | 23 | |
24 | 24 | // Read project ID from command line. |
25 | -if ($argc!=2) { |
|
26 | - die('Expected 1 command-line argument, while got ' . $argc-1); |
|
25 | +if ($argc != 2) { |
|
26 | + die('Expected 1 command-line argument, while got '.$argc - 1); |
|
27 | 27 | } |
28 | 28 | $projectId = $argv[1]; |
29 | 29 | |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | $experiments = $result->getPayload(); |
48 | 48 | |
49 | 49 | foreach ($experiments as $experiment) { |
50 | - echo "Name: " . $experiment->getName() . "\n"; |
|
51 | - echo "Description: " . $experiment->getDescription() . "\n"; |
|
52 | - echo "Status: " . $project->getStatus() . "\n"; |
|
53 | - echo "Created: " . $project->getCreated() . "\n"; |
|
50 | + echo "Name: ".$experiment->getName()."\n"; |
|
51 | + echo "Description: ".$experiment->getDescription()."\n"; |
|
52 | + echo "Status: ".$project->getStatus()."\n"; |
|
53 | + echo "Created: ".$project->getCreated()."\n"; |
|
54 | 54 | |
55 | 55 | echo "\n"; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Determine if there are more projects. |
59 | - if ($result->getNextPage()==null) |
|
59 | + if ($result->getNextPage() == null) |
|
60 | 60 | break; |
61 | 61 | |
62 | 62 | // Increment page counter. |
63 | - $page ++; |
|
63 | + $page++; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | } catch (Exception $e) { |
@@ -74,6 +74,6 @@ discard block |
||
74 | 74 | |
75 | 75 | // Save access token for later use |
76 | 76 | $accessToken = $optimizelyClient->getAccessToken(); |
77 | -file_put_contents(dirname(__FILE__) . '/../access_token.json', json_encode($accessToken)); |
|
77 | +file_put_contents(dirname(__FILE__).'/../access_token.json', json_encode($accessToken)); |
|
78 | 78 | |
79 | 79 | echo "Done!\n"; |
@@ -17,10 +17,10 @@ discard block |
||
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(); |
@@ -117,6 +117,6 @@ discard block |
||
117 | 117 | |
118 | 118 | // Save access token for later use |
119 | 119 | $accessToken = $optimizelyClient->getAccessToken(); |
120 | -file_put_contents(dirname(__FILE__) . '/../access_token.json', json_encode($accessToken)); |
|
120 | +file_put_contents(dirname(__FILE__).'/../access_token.json', json_encode($accessToken)); |
|
121 | 121 | |
122 | 122 | echo "Done!\n"; |
123 | 123 | \ No newline at end of file |
@@ -50,13 +50,13 @@ discard block |
||
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 |
||
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 |
||
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 array'); |
112 | 112 | } |
113 | 113 | |
@@ -166,16 +166,16 @@ discard block |
||
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 |
||
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 |
||
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); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | if ($result === false) { |
252 | 252 | $code = curl_errno($this->curlHandle); |
253 | 253 | $error = curl_error($this->curlHandle); |
254 | - throw new Exception("Failed to send HTTP request $method '$url', " . |
|
254 | + throw new Exception("Failed to send HTTP request $method '$url', ". |
|
255 | 255 | "the error code was $code, error message was: '$error'", |
256 | 256 | Exception::CODE_CURL_ERROR, $code, $error); |
257 | 257 | } |
@@ -265,12 +265,12 @@ discard block |
||
265 | 265 | $headers = explode("\n", $headers); |
266 | 266 | $parsedHeaders = array(); |
267 | 267 | foreach ($headers as $i=>$header) { |
268 | - if ($i==0) |
|
268 | + if ($i == 0) |
|
269 | 269 | continue; // Skip first line (http code). |
270 | 270 | $pos = strpos($header, ':'); |
271 | - if ($pos!=false) { |
|
271 | + if ($pos != false) { |
|
272 | 272 | $headerName = trim(strtolower(substr($header, 0, $pos))); |
273 | - $headerValue = trim(substr($header, $pos+1)); |
|
273 | + $headerValue = trim(substr($header, $pos + 1)); |
|
274 | 274 | $parsedHeaders[$headerName] = $headerValue; |
275 | 275 | } |
276 | 276 | } |
@@ -302,21 +302,21 @@ discard block |
||
302 | 302 | |
303 | 303 | // JSON-decode payload. |
304 | 304 | $decodedPayload = json_decode($body, true); |
305 | - if ($decodedPayload===false) { |
|
306 | - throw new Exception('Could not JSON-decode the Optimizely API response. Request was ' . |
|
307 | - $method . ' "' . $url . '". The response was: "' . $body . '"', |
|
305 | + if ($decodedPayload === false) { |
|
306 | + throw new Exception('Could not JSON-decode the Optimizely API response. Request was '. |
|
307 | + $method.' "'.$url.'". The response was: "'.$body.'"', |
|
308 | 308 | Exception::CODE_API_ERROR, array('http_code'=>$httpCode)); |
309 | 309 | } |
310 | 310 | |
311 | 311 | // Check HTTP response code. |
312 | - if ($httpCode<200 || $httpCode>299) { |
|
312 | + if ($httpCode < 200 || $httpCode > 299) { |
|
313 | 313 | |
314 | 314 | if (!isset($decodedPayload['message']) || |
315 | 315 | !isset($decodedPayload['code']) || |
316 | 316 | !isset($decodedPayload['uuid']) || |
317 | 317 | $httpCode != !isset($decodedPayload['code'])) { |
318 | - throw new Exception('Optimizely API responded with error code ' . $httpCode . |
|
319 | - ', but response format was unexpected. Request was ' . $method . ' "' . $url . '". Response was "' . $body . '"', |
|
318 | + throw new Exception('Optimizely API responded with error code '.$httpCode. |
|
319 | + ', but response format was unexpected. Request was '.$method.' "'.$url.'". Response was "'.$body.'"', |
|
320 | 320 | Exception::CODE_API_ERROR, array( |
321 | 321 | 'http_code' => $httpCode, |
322 | 322 | 'rate_limit' => $rateLimit, |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $matched = preg_match_all('/<(.+)>;\s+rel=(\w+)(,|\z)/U', |
349 | 349 | $parsedHeaders['link'], $matches, PREG_SET_ORDER); |
350 | 350 | if (!$matched) { |
351 | - throw new Exception('Error parsing LINK header: ' . |
|
351 | + throw new Exception('Error parsing LINK header: '. |
|
352 | 352 | $parsedHeaders['link'], Exception::CODE_API_ERROR, $httpCode); |
353 | 353 | } |
354 | 354 | |
@@ -358,22 +358,22 @@ discard block |
||
358 | 358 | $rel = $match[2]; |
359 | 359 | |
360 | 360 | $matched = preg_match('/page=(\d+)/U', $url, $pageMatches); |
361 | - if (!$matched || count($pageMatches)!=2) { |
|
362 | - throw new Exception('Error extracting page argument while parsing LINK header: ' . |
|
361 | + if (!$matched || count($pageMatches) != 2) { |
|
362 | + throw new Exception('Error extracting page argument while parsing LINK header: '. |
|
363 | 363 | $parsedHeaders['link'], Exception::CODE_API_ERROR, |
364 | 364 | array('http_code'=>$httpCode)); |
365 | 365 | } |
366 | 366 | |
367 | 367 | $pageNumber = $pageMatches[1]; |
368 | 368 | |
369 | - if ($rel=='prev') { |
|
369 | + if ($rel == 'prev') { |
|
370 | 370 | $result->setPrevPage($pageNumber); |
371 | - } else if ($rel=='next') { |
|
371 | + } else if ($rel == 'next') { |
|
372 | 372 | $result->setNextPage($pageNumber); |
373 | - } else if ($rel=='last') { |
|
373 | + } else if ($rel == 'last') { |
|
374 | 374 | $result->setLastPage($pageNumber); |
375 | 375 | } else { |
376 | - throw new Exception('Unexpected rel argument while parsing LINK header: ' . |
|
376 | + throw new Exception('Unexpected rel argument while parsing LINK header: '. |
|
377 | 377 | $parsedHeaders['link'], Exception::CODE_API_ERROR, |
378 | 378 | array('http_code'=>$httpCode)); |
379 | 379 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | */ |
392 | 392 | private function isAccessTokenExpired() |
393 | 393 | { |
394 | - if(!isset($this->authCredentials['access_token'])) { |
|
394 | + if (!isset($this->authCredentials['access_token'])) { |
|
395 | 395 | return true; // We do not have access token. |
396 | 396 | } |
397 | 397 | |
@@ -432,15 +432,15 @@ discard block |
||
432 | 432 | $clientSecret = $this->authCredentials['client_secret']; |
433 | 433 | $refreshToken = $this->authCredentials['refresh_token']; |
434 | 434 | |
435 | - $url = "https://app.optimizely.com/oauth2/token?refresh_token=$refreshToken" . |
|
435 | + $url = "https://app.optimizely.com/oauth2/token?refresh_token=$refreshToken". |
|
436 | 436 | "&client_id=$clientId&client_secret=$clientSecret&grant_type=refresh_token"; |
437 | 437 | |
438 | 438 | $response = $this->sendHttpRequest($url, array(), 'POST'); |
439 | 439 | $decodedJsonData = $response->getDecodedJsonData(); |
440 | 440 | |
441 | 441 | if (!isset($decodedJsonData['access_token'])) { |
442 | - throw new Exception('Not found access token in response. Request URL was "' . |
|
443 | - $url. '". Response was "' . print_r(json_encode($decodedJsonData), true). '"', |
|
442 | + throw new Exception('Not found access token in response. Request URL was "'. |
|
443 | + $url.'". Response was "'.print_r(json_encode($decodedJsonData), true).'"', |
|
444 | 444 | Exception::CODE_API_ERROR, $response->getHttpCode()); |
445 | 445 | } |
446 | 446 |
@@ -36,21 +36,21 @@ discard block |
||
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 | 41 | if (!is_int($projectId)) { |
42 | 42 | throw new Exception("Integer project ID expected, while got '$projectId'"); |
43 | 43 | } |
44 | 44 | |
45 | - if ($projectId<0) { |
|
45 | + if ($projectId < 0) { |
|
46 | 46 | throw new Exception("Expected positive integer project ID"); |
47 | 47 | } |
48 | 48 | |
49 | - if ($page<0) { |
|
49 | + if ($page < 0) { |
|
50 | 50 | throw new Exception('Invalid page number passed'); |
51 | 51 | } |
52 | 52 | |
53 | - if ($perPage<0) { |
|
53 | + if ($perPage < 0) { |
|
54 | 54 | throw new Exception('Invalid page size passed'); |
55 | 55 | } |
56 | 56 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | Exception::CODE_INVALID_ARG); |
107 | 107 | } |
108 | 108 | |
109 | - if ($campaignId<0) { |
|
109 | + if ($campaignId < 0) { |
|
110 | 110 | throw new Exception("Expected positive integer campaign ID", |
111 | 111 | Exception::CODE_INVALID_ARG); |
112 | 112 | } |