@@ -91,8 +91,9 @@ |
||
| 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; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | case 'start_time': $this->setStartTime($value); break; |
| 69 | 69 | default: |
| 70 | - throw new Exception('Unknown option: ' . $name); |
|
| 70 | + throw new Exception('Unknown option: '.$name); |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | // Remove options with empty values |
| 93 | 93 | $cleanedOptions = array(); |
| 94 | 94 | foreach ($options as $name=>$value) { |
| 95 | - if ($value!==null) |
|
| 95 | + if ($value !== null) |
|
| 96 | 96 | $cleanedOptions[$name] = $value; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | $credentials = file_get_contents(dirname(__FILE__) . '/../../../auth_credentials.json'); |
| 12 | 12 | if ($credentials===false) { |
| 13 | 13 | $this->fail("Couldn't read OAuth credentials from auth_credentials.json. Make sure " . |
| 14 | - "the file exists (if not, copy from auth_credentials.json.dist)."); |
|
| 14 | + "the file exists (if not, copy from auth_credentials.json.dist)."); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | $credentials = json_decode($credentials, true); |
@@ -8,9 +8,9 @@ discard block |
||
| 8 | 8 | public function loadCredentialsFromFile() |
| 9 | 9 | { |
| 10 | 10 | // Get OAuth 2.0 credentials from auth_credentials.json file. |
| 11 | - $credentials = file_get_contents(dirname(__FILE__) . '/../../../auth_credentials.json'); |
|
| 12 | - if ($credentials===false) { |
|
| 13 | - $this->fail("Couldn't read OAuth credentials from auth_credentials.json. Make sure " . |
|
| 11 | + $credentials = file_get_contents(dirname(__FILE__).'/../../../auth_credentials.json'); |
|
| 12 | + if ($credentials === false) { |
|
| 13 | + $this->fail("Couldn't read OAuth credentials from auth_credentials.json. Make sure ". |
|
| 14 | 14 | "the file exists (if not, copy from auth_credentials.json.dist)."); |
| 15 | 15 | } |
| 16 | 16 | |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Try to read access_token.json and merge it with the rest of credentials. |
| 23 | - if (is_readable(dirname(__FILE__) . '/../../../access_token.json')) { |
|
| 24 | - $accessToken = file_get_contents(dirname(__FILE__) . '/access_token.json'); |
|
| 23 | + if (is_readable(dirname(__FILE__).'/../../../access_token.json')) { |
|
| 24 | + $accessToken = file_get_contents(dirname(__FILE__).'/access_token.json'); |
|
| 25 | 25 | |
| 26 | 26 | $accessToken = json_decode($accessToken, true); |
| 27 | 27 | if (!is_array($accessToken)) { |
@@ -109,16 +109,16 @@ discard block |
||
| 109 | 109 | "platform" => "web", |
| 110 | 110 | "status" => "active", |
| 111 | 111 | "web_snippet" => array( |
| 112 | - "enable_force_variation" => false, |
|
| 113 | - "exclude_disabled_experiments" => false, |
|
| 114 | - "exclude_names" => true, |
|
| 115 | - "include_jquery" => true, |
|
| 116 | - "ip_anonymization" => false, |
|
| 117 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 118 | - "library" => "jquery-1.11.3-trim", |
|
| 119 | - "project_javascript" => "alert(\"Active Experiment\")", |
|
| 120 | - "code_revision" => 0, |
|
| 121 | - "js_file_size" => 63495 |
|
| 112 | + "enable_force_variation" => false, |
|
| 113 | + "exclude_disabled_experiments" => false, |
|
| 114 | + "exclude_names" => true, |
|
| 115 | + "include_jquery" => true, |
|
| 116 | + "ip_anonymization" => false, |
|
| 117 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 118 | + "library" => "jquery-1.11.3-trim", |
|
| 119 | + "project_javascript" => "alert(\"Active Experiment\")", |
|
| 120 | + "code_revision" => 0, |
|
| 121 | + "js_file_size" => 63495 |
|
| 122 | 122 | ), |
| 123 | 123 | "created" => "2016-10-17T07:04:59.991Z", |
| 124 | 124 | "id" => 1000, |
@@ -137,14 +137,14 @@ discard block |
||
| 137 | 137 | "platform" => "web", |
| 138 | 138 | "status" => "active", |
| 139 | 139 | "web_snippet" => array( |
| 140 | - "enable_force_variation" => false, |
|
| 141 | - "exclude_disabled_experiments" => false, |
|
| 142 | - "exclude_names" => true, |
|
| 143 | - "include_jquery" => true, |
|
| 144 | - "ip_anonymization" => false, |
|
| 145 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 146 | - "library" => "jquery-1.11.3-trim", |
|
| 147 | - "project_javascript" => "alert(\"Active Experiment\")" |
|
| 140 | + "enable_force_variation" => false, |
|
| 141 | + "exclude_disabled_experiments" => false, |
|
| 142 | + "exclude_names" => true, |
|
| 143 | + "include_jquery" => true, |
|
| 144 | + "ip_anonymization" => false, |
|
| 145 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 146 | + "library" => "jquery-1.11.3-trim", |
|
| 147 | + "project_javascript" => "alert(\"Active Experiment\")" |
|
| 148 | 148 | ) |
| 149 | 149 | )); |
| 150 | 150 | |
@@ -173,16 +173,16 @@ discard block |
||
| 173 | 173 | "platform" => "web", |
| 174 | 174 | "status" => "active", |
| 175 | 175 | "web_snippet" => array( |
| 176 | - "enable_force_variation" => false, |
|
| 177 | - "exclude_disabled_experiments" => false, |
|
| 178 | - "exclude_names" => true, |
|
| 179 | - "include_jquery" => true, |
|
| 180 | - "ip_anonymization" => false, |
|
| 181 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 182 | - "library" => "jquery-1.11.3-trim", |
|
| 183 | - "project_javascript" => "alert(\"Active Experiment\")", |
|
| 184 | - "code_revision" => 0, |
|
| 185 | - "js_file_size" => 63495 |
|
| 176 | + "enable_force_variation" => false, |
|
| 177 | + "exclude_disabled_experiments" => false, |
|
| 178 | + "exclude_names" => true, |
|
| 179 | + "include_jquery" => true, |
|
| 180 | + "ip_anonymization" => false, |
|
| 181 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 182 | + "library" => "jquery-1.11.3-trim", |
|
| 183 | + "project_javascript" => "alert(\"Active Experiment\")", |
|
| 184 | + "code_revision" => 0, |
|
| 185 | + "js_file_size" => 63495 |
|
| 186 | 186 | ), |
| 187 | 187 | "created" => "2016-10-17T07:04:59.999Z", |
| 188 | 188 | "id" => 1000, |
@@ -199,14 +199,14 @@ discard block |
||
| 199 | 199 | "name" => "Test Project", |
| 200 | 200 | "status" => "active", |
| 201 | 201 | "web_snippet" => array( |
| 202 | - "enable_force_variation" => false, |
|
| 203 | - "exclude_disabled_experiments" => false, |
|
| 204 | - "exclude_names" => true, |
|
| 205 | - "include_jquery" => true, |
|
| 206 | - "ip_anonymization" => false, |
|
| 207 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 208 | - "library" => "jquery-1.11.3-trim", |
|
| 209 | - "project_javascript" => "alert(\"Active Experiment\")" |
|
| 202 | + "enable_force_variation" => false, |
|
| 203 | + "exclude_disabled_experiments" => false, |
|
| 204 | + "exclude_names" => true, |
|
| 205 | + "include_jquery" => true, |
|
| 206 | + "ip_anonymization" => false, |
|
| 207 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 208 | + "library" => "jquery-1.11.3-trim", |
|
| 209 | + "project_javascript" => "alert(\"Active Experiment\")" |
|
| 210 | 210 | ) |
| 211 | 211 | )); |
| 212 | 212 | |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | "platform" => "web", |
| 237 | 237 | "status" => "active", |
| 238 | 238 | "web_snippet" => array( |
| 239 | - "enable_force_variation" => false, |
|
| 240 | - "exclude_disabled_experiments" => false, |
|
| 241 | - "exclude_names" => true, |
|
| 242 | - "include_jquery" => true, |
|
| 243 | - "ip_anonymization" => false, |
|
| 244 | - "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 245 | - "library" => "jquery-1.11.3-trim", |
|
| 246 | - "project_javascript" => "alert(\"Active Experiment\")" |
|
| 239 | + "enable_force_variation" => false, |
|
| 240 | + "exclude_disabled_experiments" => false, |
|
| 241 | + "exclude_names" => true, |
|
| 242 | + "include_jquery" => true, |
|
| 243 | + "ip_anonymization" => false, |
|
| 244 | + "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$", |
|
| 245 | + "library" => "jquery-1.11.3-trim", |
|
| 246 | + "project_javascript" => "alert(\"Active Experiment\")" |
|
| 247 | 247 | ) |
| 248 | 248 | )); |
| 249 | 249 | |
@@ -324,8 +324,9 @@ discard block |
||
| 324 | 324 | |
| 325 | 325 | public function testIntegration() |
| 326 | 326 | { |
| 327 | - if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) |
|
| 328 | - $this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set'); |
|
| 327 | + if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) { |
|
| 328 | + $this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set'); |
|
| 329 | + } |
|
| 329 | 330 | |
| 330 | 331 | $credentials = $this->loadCredentialsFromFile(); |
| 331 | 332 | |
@@ -387,13 +388,13 @@ discard block |
||
| 387 | 388 | } |
| 388 | 389 | } |
| 389 | 390 | |
| 390 | - if ($result->getNextPage()==null) |
|
| 391 | - break; |
|
| 391 | + if ($result->getNextPage()==null) { |
|
| 392 | + break; |
|
| 393 | + } |
|
| 392 | 394 | |
| 393 | 395 | $page ++; |
| 394 | 396 | } |
| 395 | - } |
|
| 396 | - catch (Exception $e) { |
|
| 397 | + } catch (Exception $e) { |
|
| 397 | 398 | // Handle error. |
| 398 | 399 | $code = $e->getCode(); |
| 399 | 400 | $httpCode = $e->getHttpCode(); |
@@ -407,8 +408,7 @@ discard block |
||
| 407 | 408 | // Try a non-existing project by ID - assume failure |
| 408 | 409 | try { |
| 409 | 410 | $result = $optimizelyClient->projects()->get(12345678); |
| 410 | - } |
|
| 411 | - catch(Exception $e) { |
|
| 411 | + } catch(Exception $e) { |
|
| 412 | 412 | //print_r($optimizelyClient->getDiagnosticsInfo()); |
| 413 | 413 | $this->assertEquals(Exception::CODE_API_ERROR, $e->getCode()); |
| 414 | 414 | $this->assertEquals('not_found', $e->getHttpCode()); |
@@ -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 | /** |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | $createdProject = $result->getPayload(); |
| 207 | 207 | |
| 208 | 208 | $this->assertTrue($createdProject instanceOf Project); |
| 209 | - $this->assertTrue($createdProject->getName()=='Test Project'); |
|
| 210 | - $this->assertTrue($createdProject->getAccountId()==12345); |
|
| 209 | + $this->assertTrue($createdProject->getName() == 'Test Project'); |
|
| 210 | + $this->assertTrue($createdProject->getAccountId() == 12345); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | $updatedProject = $result->getPayload(); |
| 287 | 287 | |
| 288 | 288 | $this->assertTrue($updatedProject instanceOf Project); |
| 289 | - $this->assertTrue($updatedProject->getName()=='Test Project'); |
|
| 290 | - $this->assertTrue($updatedProject->getAccountId()==12345); |
|
| 289 | + $this->assertTrue($updatedProject->getName() == 'Test Project'); |
|
| 290 | + $this->assertTrue($updatedProject->getAccountId() == 12345); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $credentials = $this->loadCredentialsFromFile(); |
| 331 | 331 | |
| 332 | 332 | $optimizelyClient = new OptimizelyApiClient($credentials, 'v2'); |
| 333 | - $this->assertTrue($optimizelyClient!=null); |
|
| 333 | + $this->assertTrue($optimizelyClient != null); |
|
| 334 | 334 | |
| 335 | 335 | // Create new project |
| 336 | 336 | $curDate = date('Y-m-d H:i:s'); |
@@ -381,18 +381,18 @@ discard block |
||
| 381 | 381 | $projects = $result->getPayload(); |
| 382 | 382 | |
| 383 | 383 | foreach ($projects as $project) { |
| 384 | - echo "Name: " . $project->getName() . "\n"; |
|
| 385 | - if ($project->getName()=="Test Project $curDate") { |
|
| 384 | + echo "Name: ".$project->getName()."\n"; |
|
| 385 | + if ($project->getName() == "Test Project $curDate") { |
|
| 386 | 386 | $projectId = $project->getId(); |
| 387 | 387 | $projectFound = true; |
| 388 | 388 | break; |
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - if ($result->getNextPage()==null) |
|
| 392 | + if ($result->getNextPage() == null) |
|
| 393 | 393 | break; |
| 394 | 394 | |
| 395 | - $page ++; |
|
| 395 | + $page++; |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | catch (Exception $e) { |
@@ -410,11 +410,11 @@ discard block |
||
| 410 | 410 | try { |
| 411 | 411 | $result = $optimizelyClient->projects()->get(12345678); |
| 412 | 412 | } |
| 413 | - catch(Exception $e) { |
|
| 413 | + catch (Exception $e) { |
|
| 414 | 414 | //print_r($optimizelyClient->getDiagnosticsInfo()); |
| 415 | 415 | $this->assertEquals(Exception::CODE_API_ERROR, $e->getCode()); |
| 416 | 416 | $this->assertEquals('not_found', $e->getHttpCode()); |
| 417 | - $this->assertTrue(strlen($e->getUuid())!=0); |
|
| 417 | + $this->assertTrue(strlen($e->getUuid()) != 0); |
|
| 418 | 418 | //$this->assertTrue($e->getRateLimit()>0); |
| 419 | 419 | //$this->assertTrue($e->getRateLimitRemaining()>0); |
| 420 | 420 | //$this->assertTrue($e->getRateLimitReset()>0); |
@@ -13,47 +13,47 @@ discard block |
||
| 13 | 13 | "confidence_threshold" => 0, |
| 14 | 14 | "end_time" => "2016-10-14T05:08:42.966Z", |
| 15 | 15 | "metrics" => array( |
| 16 | - array( |
|
| 16 | + array( |
|
| 17 | 17 | "event" => "string", |
| 18 | 18 | "event_name" => "string", |
| 19 | 19 | "measure" => "conversions", |
| 20 | 20 | "metric_id" => "string", |
| 21 | 21 | "priority" => 0, |
| 22 | 22 | "results" => array( |
| 23 | - "campaign" => array( |
|
| 23 | + "campaign" => array( |
|
| 24 | 24 | "experiment_id" => 0, |
| 25 | 25 | "is_baseline" => true, |
| 26 | 26 | "lift" => array( |
| 27 | - "confidence_interval" => array( |
|
| 27 | + "confidence_interval" => array( |
|
| 28 | 28 | 0.010399560300730457, |
| 29 | 29 | 0.0850821459929161 |
| 30 | - ), |
|
| 31 | - "is_most_conclusive" => true, |
|
| 32 | - "is_significant" => true, |
|
| 33 | - "significance" => 0, |
|
| 34 | - "value" => 0, |
|
| 35 | - "visitors_remaining" => 0 |
|
| 30 | + ), |
|
| 31 | + "is_most_conclusive" => true, |
|
| 32 | + "is_significant" => true, |
|
| 33 | + "significance" => 0, |
|
| 34 | + "value" => 0, |
|
| 35 | + "visitors_remaining" => 0 |
|
| 36 | 36 | ), |
| 37 | 37 | "name" => "Blue Button", |
| 38 | 38 | "rate" => 0, |
| 39 | 39 | "scope" => "variation", |
| 40 | 40 | "total_increase" => array( |
| 41 | - "confidence_interval" => array( |
|
| 41 | + "confidence_interval" => array( |
|
| 42 | 42 | 0.010399560300730457, |
| 43 | 43 | 0.0850821459929161 |
| 44 | - ), |
|
| 45 | - "is_most_conclusive" => true, |
|
| 46 | - "is_significant" => true, |
|
| 47 | - "significance" => 0, |
|
| 48 | - "value" => 0, |
|
| 49 | - "visitors_remaining" => 0 |
|
| 44 | + ), |
|
| 45 | + "is_most_conclusive" => true, |
|
| 46 | + "is_significant" => true, |
|
| 47 | + "significance" => 0, |
|
| 48 | + "value" => 0, |
|
| 49 | + "visitors_remaining" => 0 |
|
| 50 | 50 | ), |
| 51 | 51 | "value" => 0, |
| 52 | 52 | "variation_id" => "string" |
| 53 | - ) |
|
| 53 | + ) |
|
| 54 | 54 | ), |
| 55 | 55 | "unit" => "session" |
| 56 | - ) |
|
| 56 | + ) |
|
| 57 | 57 | ), |
| 58 | 58 | "start_time" => "2016-10-14T05:08:42.967Z" |
| 59 | 59 | ); |
@@ -71,47 +71,47 @@ discard block |
||
| 71 | 71 | "confidence_threshold" => 0, |
| 72 | 72 | "end_time" => "2016-10-14T05:08:42.966Z", |
| 73 | 73 | "metrics" => array( |
| 74 | - array( |
|
| 74 | + array( |
|
| 75 | 75 | "event" => "string", |
| 76 | 76 | "event_name" => "string", |
| 77 | 77 | "measure" => "conversions", |
| 78 | 78 | "metric_id" => "string", |
| 79 | 79 | "priority" => 0, |
| 80 | 80 | "results" => array( |
| 81 | - "campaign" => array( |
|
| 81 | + "campaign" => array( |
|
| 82 | 82 | "experiment_id" => 0, |
| 83 | 83 | "is_baseline" => true, |
| 84 | 84 | "lift" => array( |
| 85 | - "confidence_interval" => array( |
|
| 85 | + "confidence_interval" => array( |
|
| 86 | 86 | 0.010399560300730457, |
| 87 | 87 | 0.0850821459929161 |
| 88 | - ), |
|
| 89 | - "is_most_conclusive" => true, |
|
| 90 | - "is_significant" => true, |
|
| 91 | - "significance" => 0, |
|
| 92 | - "value" => 0, |
|
| 93 | - "visitors_remaining" => 0 |
|
| 88 | + ), |
|
| 89 | + "is_most_conclusive" => true, |
|
| 90 | + "is_significant" => true, |
|
| 91 | + "significance" => 0, |
|
| 92 | + "value" => 0, |
|
| 93 | + "visitors_remaining" => 0 |
|
| 94 | 94 | ), |
| 95 | 95 | "name" => "Blue Button", |
| 96 | 96 | "rate" => 0, |
| 97 | 97 | "scope" => "variation", |
| 98 | 98 | "total_increase" => array( |
| 99 | - "confidence_interval" => array( |
|
| 99 | + "confidence_interval" => array( |
|
| 100 | 100 | 0.010399560300730457, |
| 101 | 101 | 0.0850821459929161 |
| 102 | - ), |
|
| 103 | - "is_most_conclusive" => true, |
|
| 104 | - "is_significant" => true, |
|
| 105 | - "significance" => 0, |
|
| 106 | - "value" => 0, |
|
| 107 | - "visitors_remaining" => 0 |
|
| 102 | + ), |
|
| 103 | + "is_most_conclusive" => true, |
|
| 104 | + "is_significant" => true, |
|
| 105 | + "significance" => 0, |
|
| 106 | + "value" => 0, |
|
| 107 | + "visitors_remaining" => 0 |
|
| 108 | 108 | ), |
| 109 | 109 | "value" => 0, |
| 110 | 110 | "variation_id" => "string" |
| 111 | - ) |
|
| 111 | + ) |
|
| 112 | 112 | ), |
| 113 | 113 | "unit" => "session" |
| 114 | - ) |
|
| 114 | + ) |
|
| 115 | 115 | ), |
| 116 | 116 | "start_time" => "2016-10-14T05:08:42.967Z" |
| 117 | 117 | ); |
@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | $audience->setConditions(array( |
| 15 | 15 | "and", |
| 16 | 16 | array( |
| 17 | - "value" => "es", |
|
| 18 | - "type" => "language" |
|
| 17 | + "value" => "es", |
|
| 18 | + "type" => "language" |
|
| 19 | 19 | ), |
| 20 | 20 | array( |
| 21 | - "value" => "US-CA-SANFRANCISCO", |
|
| 22 | - "type" => "location" |
|
| 21 | + "value" => "US-CA-SANFRANCISCO", |
|
| 22 | + "type" => "location" |
|
| 23 | 23 | ) |
| 24 | 24 | )); |
| 25 | 25 | $audience->setDescription('People that speak spanish and are in San Francisco'); |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | "project_id" => 1000, |
| 47 | 47 | "archived" => false, |
| 48 | 48 | "conditions" => array( |
| 49 | - "and", |
|
| 50 | - array( |
|
| 49 | + "and", |
|
| 50 | + array( |
|
| 51 | 51 | "value" => "es", |
| 52 | 52 | "type" => "language" |
| 53 | - ), |
|
| 54 | - array( |
|
| 53 | + ), |
|
| 54 | + array( |
|
| 55 | 55 | "value" => "US-CA-SANFRANCISCO", |
| 56 | 56 | "type" => "location" |
| 57 | - ) |
|
| 57 | + ) |
|
| 58 | 58 | ), |
| 59 | 59 | "description" => "People that speak spanish and are in San Francisco", |
| 60 | 60 | "name" => "Spanish speaking San Franciscans", |
@@ -77,15 +77,15 @@ discard block |
||
| 77 | 77 | "project_id" => 1000, |
| 78 | 78 | "archived" => false, |
| 79 | 79 | "conditions" => array( |
| 80 | - "and", |
|
| 81 | - array( |
|
| 80 | + "and", |
|
| 81 | + array( |
|
| 82 | 82 | "value" => "es", |
| 83 | 83 | "type" => "language" |
| 84 | - ), |
|
| 85 | - array( |
|
| 84 | + ), |
|
| 85 | + array( |
|
| 86 | 86 | "value" => "US-CA-SANFRANCISCO", |
| 87 | 87 | "type" => "location" |
| 88 | - ) |
|
| 88 | + ) |
|
| 89 | 89 | ), |
| 90 | 90 | "description" => "People that speak spanish and are in San Francisco", |
| 91 | 91 | "name" => "Spanish speaking San Franciscans", |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | "end_time" => "2016-10-14T05:08:43.031Z", |
| 14 | 14 | "experiment_id" => 3000, |
| 15 | 15 | "metrics" => array( |
| 16 | - array( |
|
| 16 | + array( |
|
| 17 | 17 | "event" => "string", |
| 18 | 18 | "event_name" => "string", |
| 19 | 19 | "measure" => "conversions", |
@@ -21,54 +21,54 @@ discard block |
||
| 21 | 21 | "priority" => 1, |
| 22 | 22 | "unit" => "session", |
| 23 | 23 | "variation_results" => array( |
| 24 | - "9000" => array( |
|
| 24 | + "9000" => array( |
|
| 25 | 25 | "experiment_id" => 0, |
| 26 | 26 | "is_baseline" => true, |
| 27 | 27 | "lift" => array( |
| 28 | - "confidence_interval" => array( |
|
| 28 | + "confidence_interval" => array( |
|
| 29 | 29 | 0.010399560300730457, |
| 30 | 30 | 0.0850821459929161 |
| 31 | - ), |
|
| 32 | - "is_most_conclusive" => true, |
|
| 33 | - "is_significant" => true, |
|
| 34 | - "significance" => 0, |
|
| 35 | - "value" => 0, |
|
| 36 | - "visitors_remaining" => 0 |
|
| 31 | + ), |
|
| 32 | + "is_most_conclusive" => true, |
|
| 33 | + "is_significant" => true, |
|
| 34 | + "significance" => 0, |
|
| 35 | + "value" => 0, |
|
| 36 | + "visitors_remaining" => 0 |
|
| 37 | 37 | ), |
| 38 | 38 | "name" => "Blue Button", |
| 39 | 39 | "rate" => 0, |
| 40 | 40 | "scope" => "variation", |
| 41 | 41 | "total_increase" => array( |
| 42 | - "confidence_interval" => array( |
|
| 42 | + "confidence_interval" => array( |
|
| 43 | 43 | 0.010399560300730457, |
| 44 | 44 | 0.0850821459929161 |
| 45 | - ), |
|
| 46 | - "is_most_conclusive" => true, |
|
| 47 | - "is_significant" => true, |
|
| 48 | - "significance" => 0, |
|
| 49 | - "value" => 0, |
|
| 50 | - "visitors_remaining" => 0 |
|
| 45 | + ), |
|
| 46 | + "is_most_conclusive" => true, |
|
| 47 | + "is_significant" => true, |
|
| 48 | + "significance" => 0, |
|
| 49 | + "value" => 0, |
|
| 50 | + "visitors_remaining" => 0 |
|
| 51 | 51 | ), |
| 52 | 52 | "value" => 0, |
| 53 | 53 | "variation_id" => "string" |
| 54 | - ) |
|
| 54 | + ) |
|
| 55 | + ) |
|
| 55 | 56 | ) |
| 56 | - ) |
|
| 57 | 57 | ), |
| 58 | 58 | "reach" => array( |
| 59 | - "baseline_count" => 0, |
|
| 60 | - "baseline_reach" => 0, |
|
| 61 | - "total_count" => 0, |
|
| 62 | - "treatment_count" => 0, |
|
| 63 | - "treatment_reach" => 0, |
|
| 64 | - "variations" => array( |
|
| 59 | + "baseline_count" => 0, |
|
| 60 | + "baseline_reach" => 0, |
|
| 61 | + "total_count" => 0, |
|
| 62 | + "treatment_count" => 0, |
|
| 63 | + "treatment_reach" => 0, |
|
| 64 | + "variations" => array( |
|
| 65 | 65 | "9000" => array( |
| 66 | - "count" => 0, |
|
| 67 | - "name" => "Blue Button", |
|
| 68 | - "variation_id" => "string", |
|
| 69 | - "variation_reach" => 0 |
|
| 66 | + "count" => 0, |
|
| 67 | + "name" => "Blue Button", |
|
| 68 | + "variation_id" => "string", |
|
| 69 | + "variation_reach" => 0 |
|
| 70 | + ) |
|
| 70 | 71 | ) |
| 71 | - ) |
|
| 72 | 72 | ), |
| 73 | 73 | "start_time" => "2016-10-14T05:08:43.032Z" |
| 74 | 74 | ); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | "end_time" => "2016-10-14T05:08:43.031Z", |
| 87 | 87 | "experiment_id" => 3000, |
| 88 | 88 | "metrics" => array( |
| 89 | - array( |
|
| 89 | + array( |
|
| 90 | 90 | "event" => "string", |
| 91 | 91 | "event_name" => "string", |
| 92 | 92 | "measure" => "conversions", |
@@ -94,54 +94,54 @@ discard block |
||
| 94 | 94 | "priority" => 1, |
| 95 | 95 | "unit" => "session", |
| 96 | 96 | "variation_results" => array( |
| 97 | - "9000" => array( |
|
| 97 | + "9000" => array( |
|
| 98 | 98 | "experiment_id" => 0, |
| 99 | 99 | "is_baseline" => true, |
| 100 | 100 | "lift" => array( |
| 101 | - "confidence_interval" => array( |
|
| 101 | + "confidence_interval" => array( |
|
| 102 | 102 | 0.010399560300730457, |
| 103 | 103 | 0.0850821459929161 |
| 104 | - ), |
|
| 105 | - "is_most_conclusive" => true, |
|
| 106 | - "is_significant" => true, |
|
| 107 | - "significance" => 0, |
|
| 108 | - "value" => 0, |
|
| 109 | - "visitors_remaining" => 0 |
|
| 104 | + ), |
|
| 105 | + "is_most_conclusive" => true, |
|
| 106 | + "is_significant" => true, |
|
| 107 | + "significance" => 0, |
|
| 108 | + "value" => 0, |
|
| 109 | + "visitors_remaining" => 0 |
|
| 110 | 110 | ), |
| 111 | 111 | "name" => "Blue Button", |
| 112 | 112 | "rate" => 0, |
| 113 | 113 | "scope" => "variation", |
| 114 | 114 | "total_increase" => array( |
| 115 | - "confidence_interval" => array( |
|
| 115 | + "confidence_interval" => array( |
|
| 116 | 116 | 0.010399560300730457, |
| 117 | 117 | 0.0850821459929161 |
| 118 | - ), |
|
| 119 | - "is_most_conclusive" => true, |
|
| 120 | - "is_significant" => true, |
|
| 121 | - "significance" => 0, |
|
| 122 | - "value" => 0, |
|
| 123 | - "visitors_remaining" => 0 |
|
| 118 | + ), |
|
| 119 | + "is_most_conclusive" => true, |
|
| 120 | + "is_significant" => true, |
|
| 121 | + "significance" => 0, |
|
| 122 | + "value" => 0, |
|
| 123 | + "visitors_remaining" => 0 |
|
| 124 | 124 | ), |
| 125 | 125 | "value" => 0, |
| 126 | 126 | "variation_id" => "string" |
| 127 | - ) |
|
| 127 | + ) |
|
| 128 | + ) |
|
| 128 | 129 | ) |
| 129 | - ) |
|
| 130 | 130 | ), |
| 131 | 131 | "reach" => array( |
| 132 | - "baseline_count" => 0, |
|
| 133 | - "baseline_reach" => 0, |
|
| 134 | - "total_count" => 0, |
|
| 135 | - "treatment_count" => 0, |
|
| 136 | - "treatment_reach" => 0, |
|
| 137 | - "variations" => array( |
|
| 132 | + "baseline_count" => 0, |
|
| 133 | + "baseline_reach" => 0, |
|
| 134 | + "total_count" => 0, |
|
| 135 | + "treatment_count" => 0, |
|
| 136 | + "treatment_reach" => 0, |
|
| 137 | + "variations" => array( |
|
| 138 | 138 | "9000" => array( |
| 139 | - "count" => 0, |
|
| 140 | - "name" => "Blue Button", |
|
| 141 | - "variation_id" => "string", |
|
| 142 | - "variation_reach" => 0 |
|
| 139 | + "count" => 0, |
|
| 140 | + "name" => "Blue Button", |
|
| 141 | + "variation_id" => "string", |
|
| 142 | + "variation_reach" => 0 |
|
| 143 | + ) |
|
| 143 | 144 | ) |
| 144 | - ) |
|
| 145 | 145 | ), |
| 146 | 146 | "start_time" => "2016-10-14T05:08:43.032Z" |
| 147 | 147 | ); |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | "category" => "add_to_cart", |
| 44 | 44 | "description" => "Item added to cart", |
| 45 | 45 | "event_filter" => array( |
| 46 | - "filter_type" => "target_selector", |
|
| 47 | - "selector" => ".menu-options" |
|
| 46 | + "filter_type" => "target_selector", |
|
| 47 | + "selector" => ".menu-options" |
|
| 48 | 48 | ), |
| 49 | 49 | "event_type" => "custom", |
| 50 | 50 | "key" => "add_to_cart", |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | "category" => "add_to_cart", |
| 74 | 74 | "description" => "Item added to cart", |
| 75 | 75 | "event_filter" => array( |
| 76 | - "filter_type" => "target_selector", |
|
| 77 | - "selector" => ".menu-options" |
|
| 76 | + "filter_type" => "target_selector", |
|
| 77 | + "selector" => ".menu-options" |
|
| 78 | 78 | ), |
| 79 | 79 | "event_type" => "custom", |
| 80 | 80 | "key" => "add_to_cart", |
@@ -13,9 +13,9 @@ discard block |
||
| 13 | 13 | function load_credentials_from_file() |
| 14 | 14 | { |
| 15 | 15 | // Get OAuth 2.0 credentials from auth_credentials.json file. |
| 16 | - $credentials = file_get_contents(dirname(__FILE__) . '/auth_credentials.json'); |
|
| 17 | - if ($credentials===false) { |
|
| 18 | - throw new \Exception("Couldn't read OAuth credentials from auth_credentials.json. Make sure " . |
|
| 16 | + $credentials = file_get_contents(dirname(__FILE__).'/auth_credentials.json'); |
|
| 17 | + if ($credentials === false) { |
|
| 18 | + throw new \Exception("Couldn't read OAuth credentials from auth_credentials.json. Make sure ". |
|
| 19 | 19 | "the file exists (if not, copy from auth_credentials.json.dist)."); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // Try to read access_token.json and merge it with the rest of credentials. |
| 28 | - if (is_readable(dirname(__FILE__) . '/access_token.json')) { |
|
| 29 | - $accessToken = file_get_contents(dirname(__FILE__) . '/access_token.json'); |
|
| 28 | + if (is_readable(dirname(__FILE__).'/access_token.json')) { |
|
| 29 | + $accessToken = file_get_contents(dirname(__FILE__).'/access_token.json'); |
|
| 30 | 30 | |
| 31 | 31 | $accessToken = json_decode($accessToken, true); |
| 32 | 32 | if (!is_array($accessToken)) { |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | $credentials = file_get_contents(dirname(__FILE__) . '/auth_credentials.json'); |
| 17 | 17 | if ($credentials===false) { |
| 18 | 18 | throw new \Exception("Couldn't read OAuth credentials from auth_credentials.json. Make sure " . |
| 19 | - "the file exists (if not, copy from auth_credentials.json.dist)."); |
|
| 19 | + "the file exists (if not, copy from auth_credentials.json.dist)."); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | $credentials = json_decode($credentials, true); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @param array $queryParams The list of query parameters. |
| 164 | 164 | * @param string $method HTTP method (GET or POST). |
| 165 | 165 | * @param array $postData Data send in request body (only for POST method). |
| 166 | - * @return array Optimizely response in form of array. |
|
| 166 | + * @return Result Optimizely response in form of array. |
|
| 167 | 167 | * @throws Exception |
| 168 | 168 | */ |
| 169 | 169 | public function sendApiRequest($url, $queryParams = array(), $method='GET', |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @param array $queryParams The list of query parameters. |
| 189 | 189 | * @param string $method HTTP method (GET or POST). |
| 190 | 190 | * @param array $postData Data send in request body (only for POST method). |
| 191 | - * @return array Optimizely response in form of array. |
|
| 191 | + * @return Result Optimizely response in form of array. |
|
| 192 | 192 | * @throws Exception |
| 193 | 193 | */ |
| 194 | 194 | private function sendHttpRequest($url, $queryParams = array(), $method='GET', |
@@ -265,8 +265,10 @@ discard block |
||
| 265 | 265 | $headers = explode("\n", $headers); |
| 266 | 266 | $parsedHeaders = array(); |
| 267 | 267 | foreach ($headers as $i=>$header) { |
| 268 | - if ($i==0) |
|
| 269 | - continue; // Skip first line (http code). |
|
| 268 | + if ($i==0) { |
|
| 269 | + continue; |
|
| 270 | + } |
|
| 271 | + // Skip first line (http code). |
|
| 270 | 272 | $pos = strpos($header, ':'); |
| 271 | 273 | if ($pos!=false) { |
| 272 | 274 | $headerName = trim(strtolower(substr($header, 0, $pos))); |
@@ -419,14 +421,17 @@ discard block |
||
| 419 | 421 | */ |
| 420 | 422 | private function getAccessTokenByRefreshToken() |
| 421 | 423 | { |
| 422 | - if (!isset($this->authCredentials['client_id'])) |
|
| 423 | - throw new Exception('OAuth 2.0 client ID is not set'); |
|
| 424 | + if (!isset($this->authCredentials['client_id'])) { |
|
| 425 | + throw new Exception('OAuth 2.0 client ID is not set'); |
|
| 426 | + } |
|
| 424 | 427 | |
| 425 | - if (!isset($this->authCredentials['client_secret'])) |
|
| 426 | - throw new Exception('OAuth 2.0 client secret is not set'); |
|
| 428 | + if (!isset($this->authCredentials['client_secret'])) { |
|
| 429 | + throw new Exception('OAuth 2.0 client secret is not set'); |
|
| 430 | + } |
|
| 427 | 431 | |
| 428 | - if (!isset($this->authCredentials['refresh_token'])) |
|
| 429 | - throw new Exception('Refresh token is not set'); |
|
| 432 | + if (!isset($this->authCredentials['refresh_token'])) { |
|
| 433 | + throw new Exception('Refresh token is not set'); |
|
| 434 | + } |
|
| 430 | 435 | |
| 431 | 436 | $clientId = $this->authCredentials['client_id']; |
| 432 | 437 | $clientSecret = $this->authCredentials['client_secret']; |
@@ -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,36 +199,36 @@ 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 | // Reset CURL state. |
| 234 | 234 | if (!function_exists('curl_reset')) { |
@@ -241,7 +241,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |