@@ -82,7 +82,6 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * Set HTTP response code. |
| 85 | - * @param integer $code |
|
| 86 | 85 | */ |
| 87 | 86 | public function setHttpCode($httpCode) |
| 88 | 87 | { |
@@ -100,7 +99,6 @@ discard block |
||
| 100 | 99 | |
| 101 | 100 | /** |
| 102 | 101 | * Set message |
| 103 | - * @param string $message |
|
| 104 | 102 | */ |
| 105 | 103 | public function setUuid($uuid) |
| 106 | 104 | { |
@@ -145,7 +143,7 @@ discard block |
||
| 145 | 143 | |
| 146 | 144 | /** |
| 147 | 145 | * Return the exact time that your fresh new rate limit kicks in. |
| 148 | - * @return integer|null |
|
| 146 | + * @return string |
|
| 149 | 147 | */ |
| 150 | 148 | public function getRateLimitReset() |
| 151 | 149 | { |
@@ -70,8 +70,6 @@ discard block |
||
| 70 | 70 | /** |
| 71 | 71 | * Constructor. |
| 72 | 72 | * @param array $decodedJsonData |
| 73 | - * @param string $rawHttpResponseData |
|
| 74 | - * @param array[string] $rawHttpResponseHeaders |
|
| 75 | 73 | */ |
| 76 | 74 | public function __construct($decodedJsonData, $httpCode) |
| 77 | 75 | { |
@@ -90,7 +88,6 @@ discard block |
||
| 90 | 88 | |
| 91 | 89 | /** |
| 92 | 90 | * Set HTTP response code. |
| 93 | - * @param integer $code |
|
| 94 | 91 | */ |
| 95 | 92 | public function setHttpCode($httpCode) |
| 96 | 93 | { |
@@ -108,7 +105,7 @@ discard block |
||
| 108 | 105 | |
| 109 | 106 | /** |
| 110 | 107 | * Set payload (parsed and wrapped response data). |
| 111 | - * @param mixed $payload |
|
| 108 | + * @param integer $payload |
|
| 112 | 109 | */ |
| 113 | 110 | public function setPayload($payload) |
| 114 | 111 | { |
@@ -225,7 +222,7 @@ discard block |
||
| 225 | 222 | |
| 226 | 223 | /** |
| 227 | 224 | * Return the exact time that your fresh new rate limit kicks in. |
| 228 | - * @return integer|null |
|
| 225 | + * @return string |
|
| 229 | 226 | */ |
| 230 | 227 | public function getRateLimitReset() |
| 231 | 228 | { |
@@ -176,16 +176,16 @@ discard block |
||
| 176 | 176 | "platform" => "web", |
| 177 | 177 | "status" => "active", |
| 178 | 178 | "web_snippet" => array( |
| 179 | - "enable_force_variation" => false, |
|
| 180 | - "exclude_disabled_experiments" => false, |
|
| 181 | - "exclude_names" => true, |
|
| 182 | - "include_jquery" => true, |
|
| 183 | - "ip_anonymization" => false, |
|
| 184 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 185 | - "library" => "jquery-1.11.3-trim", |
|
| 186 | - "project_javascript" => "alert(\"Active Experiment\")", |
|
| 187 | - "code_revision" => 0, |
|
| 188 | - "js_file_size" => 63495 |
|
| 179 | + "enable_force_variation" => false, |
|
| 180 | + "exclude_disabled_experiments" => false, |
|
| 181 | + "exclude_names" => true, |
|
| 182 | + "include_jquery" => true, |
|
| 183 | + "ip_anonymization" => false, |
|
| 184 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 185 | + "library" => "jquery-1.11.3-trim", |
|
| 186 | + "project_javascript" => "alert(\"Active Experiment\")", |
|
| 187 | + "code_revision" => 0, |
|
| 188 | + "js_file_size" => 63495 |
|
| 189 | 189 | ), |
| 190 | 190 | "created" => "2016-10-17T07:04:59.991Z", |
| 191 | 191 | "id" => 1000, |
@@ -206,14 +206,14 @@ discard block |
||
| 206 | 206 | "platform" => "web", |
| 207 | 207 | "status" => "active", |
| 208 | 208 | "web_snippet" => array( |
| 209 | - "enable_force_variation" => false, |
|
| 210 | - "exclude_disabled_experiments" => false, |
|
| 211 | - "exclude_names" => true, |
|
| 212 | - "include_jquery" => true, |
|
| 213 | - "ip_anonymization" => false, |
|
| 214 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 215 | - "library" => "jquery-1.11.3-trim", |
|
| 216 | - "project_javascript" => "alert(\"Active Experiment\")" |
|
| 209 | + "enable_force_variation" => false, |
|
| 210 | + "exclude_disabled_experiments" => false, |
|
| 211 | + "exclude_names" => true, |
|
| 212 | + "include_jquery" => true, |
|
| 213 | + "ip_anonymization" => false, |
|
| 214 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 215 | + "library" => "jquery-1.11.3-trim", |
|
| 216 | + "project_javascript" => "alert(\"Active Experiment\")" |
|
| 217 | 217 | ) |
| 218 | 218 | )); |
| 219 | 219 | |
@@ -257,16 +257,16 @@ discard block |
||
| 257 | 257 | "platform" => "web", |
| 258 | 258 | "status" => "active", |
| 259 | 259 | "web_snippet" => array( |
| 260 | - "enable_force_variation" => false, |
|
| 261 | - "exclude_disabled_experiments" => false, |
|
| 262 | - "exclude_names" => true, |
|
| 263 | - "include_jquery" => true, |
|
| 264 | - "ip_anonymization" => false, |
|
| 265 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 266 | - "library" => "jquery-1.11.3-trim", |
|
| 267 | - "project_javascript" => "alert(\"Active Experiment\")", |
|
| 268 | - "code_revision" => 0, |
|
| 269 | - "js_file_size" => 63495 |
|
| 260 | + "enable_force_variation" => false, |
|
| 261 | + "exclude_disabled_experiments" => false, |
|
| 262 | + "exclude_names" => true, |
|
| 263 | + "include_jquery" => true, |
|
| 264 | + "ip_anonymization" => false, |
|
| 265 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 266 | + "library" => "jquery-1.11.3-trim", |
|
| 267 | + "project_javascript" => "alert(\"Active Experiment\")", |
|
| 268 | + "code_revision" => 0, |
|
| 269 | + "js_file_size" => 63495 |
|
| 270 | 270 | ), |
| 271 | 271 | "created" => "2016-10-17T07:04:59.999Z", |
| 272 | 272 | "id" => 1000, |
@@ -286,14 +286,14 @@ discard block |
||
| 286 | 286 | "name" => "Test Project", |
| 287 | 287 | "status" => "active", |
| 288 | 288 | "web_snippet" => array( |
| 289 | - "enable_force_variation" => false, |
|
| 290 | - "exclude_disabled_experiments" => false, |
|
| 291 | - "exclude_names" => true, |
|
| 292 | - "include_jquery" => true, |
|
| 293 | - "ip_anonymization" => false, |
|
| 294 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 295 | - "library" => "jquery-1.11.3-trim", |
|
| 296 | - "project_javascript" => "alert(\"Active Experiment\")" |
|
| 289 | + "enable_force_variation" => false, |
|
| 290 | + "exclude_disabled_experiments" => false, |
|
| 291 | + "exclude_names" => true, |
|
| 292 | + "include_jquery" => true, |
|
| 293 | + "ip_anonymization" => false, |
|
| 294 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 295 | + "library" => "jquery-1.11.3-trim", |
|
| 296 | + "project_javascript" => "alert(\"Active Experiment\")" |
|
| 297 | 297 | ) |
| 298 | 298 | )); |
| 299 | 299 | |
@@ -51,9 +51,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -356,8 +356,9 @@ discard block |
||
| 356 | 356 | |
| 357 | 357 | public function testIntegration() |
| 358 | 358 | { |
| 359 | - if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) |
|
| 360 | - $this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set'); |
|
| 359 | + if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) { |
|
| 360 | + $this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set'); |
|
| 361 | + } |
|
| 361 | 362 | |
| 362 | 363 | $credentials = $this->loadCredentialsFromFile(); |
| 363 | 364 | |
@@ -415,13 +416,13 @@ discard block |
||
| 415 | 416 | } |
| 416 | 417 | } |
| 417 | 418 | |
| 418 | - if ($result->getNextPage()==null) |
|
| 419 | - break; |
|
| 419 | + if ($result->getNextPage()==null) { |
|
| 420 | + break; |
|
| 421 | + } |
|
| 420 | 422 | |
| 421 | 423 | $page ++; |
| 422 | 424 | } |
| 423 | - } |
|
| 424 | - catch (Exception $e) { |
|
| 425 | + } catch (Exception $e) { |
|
| 425 | 426 | print_r($optimizelyClient->getDiagnosticsInfo()); |
| 426 | 427 | // Handle error. |
| 427 | 428 | $code = $e->getCode(); |
@@ -436,8 +437,7 @@ discard block |
||
| 436 | 437 | // Try a non-existing project by ID - assume failure |
| 437 | 438 | try { |
| 438 | 439 | $result = $optimizelyClient->projects()->get(12345678); |
| 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 | 443 | $this->assertTrue(strlen($e->getUuid())!=0); |
@@ -163,8 +163,7 @@ |
||
| 163 | 163 | // refresh token, since the provided access token is invalid. |
| 164 | 164 | try { |
| 165 | 165 | $result = $client->sendApiRequest('/projects'); |
| 166 | - } |
|
| 167 | - catch (Exception $e) { |
|
| 166 | + } catch (Exception $e) { |
|
| 168 | 167 | $this->assertEquals(Exception::CODE_API_ERROR, $e->getCode()); |
| 169 | 168 | $this->assertEquals(400, $e->getHttpCode()); |
| 170 | 169 | } |
@@ -16,14 +16,14 @@ |
||
| 16 | 16 | "platform" => "web", |
| 17 | 17 | "status" => "active", |
| 18 | 18 | "web_snippet" => array( |
| 19 | - "enable_force_variation" => false, |
|
| 20 | - "exclude_disabled_experiments" => false, |
|
| 21 | - "exclude_names" => true, |
|
| 22 | - "include_jquery" => true, |
|
| 23 | - "ip_anonymization" => false, |
|
| 24 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 25 | - "library" => "jquery-1.11.3-trim", |
|
| 26 | - "project_javascript" => "alert(\"Active Experiment\")" |
|
| 19 | + "enable_force_variation" => false, |
|
| 20 | + "exclude_disabled_experiments" => false, |
|
| 21 | + "exclude_names" => true, |
|
| 22 | + "include_jquery" => true, |
|
| 23 | + "ip_anonymization" => false, |
|
| 24 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 25 | + "library" => "jquery-1.11.3-trim", |
|
| 26 | + "project_javascript" => "alert(\"Active Experiment\")" |
|
| 27 | 27 | )); |
| 28 | 28 | |
| 29 | 29 | $result = new Result($data, 200); |
@@ -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 non-empty 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); |
@@ -252,7 +252,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -37,21 +37,21 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -36,13 +36,13 @@ |
||
| 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 | |
@@ -39,17 +39,17 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | |