@@ -51,8 +51,9 @@ |
||
| 51 | 51 | // Remove options with empty values |
| 52 | 52 | $cleanedOptions = array(); |
| 53 | 53 | foreach ($options as $name=>$value) { |
| 54 | - if ($value!==null) |
|
| 55 | - $cleanedOptions[$name] = $value; |
|
| 54 | + if ($value!==null) { |
|
| 55 | + $cleanedOptions[$name] = $value; |
|
| 56 | + } |
|
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | return $cleanedOptions; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | case 'variation_id': $this->setVariationId($value); break; |
| 50 | 50 | case 'variation_reach': $this->setVariationReach($value); break; |
| 51 | 51 | default: |
| 52 | - throw new Exception('Unknown option: ' . $name); |
|
| 52 | + throw new Exception('Unknown option: '.$name); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | // Remove options with empty values |
| 70 | 70 | $cleanedOptions = array(); |
| 71 | 71 | foreach ($options as $name=>$value) { |
| 72 | - if ($value!==null) |
|
| 72 | + if ($value !== null) |
|
| 73 | 73 | $cleanedOptions[$name] = $value; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -51,8 +51,9 @@ |
||
| 51 | 51 | // Remove options with empty values |
| 52 | 52 | $cleanedOptions = array(); |
| 53 | 53 | foreach ($options as $name=>$value) { |
| 54 | - if ($value!==null) |
|
| 55 | - $cleanedOptions[$name] = $value; |
|
| 54 | + if ($value!==null) { |
|
| 55 | + $cleanedOptions[$name] = $value; |
|
| 56 | + } |
|
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | return $cleanedOptions; |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | case 'id': $this->setId($value); break; |
| 162 | 162 | case 'is_classic': $this->setIsClassic($value); break; |
| 163 | 163 | default: |
| 164 | - throw new Exception('Unknown option: ' . $name); |
|
| 164 | + throw new Exception('Unknown option: '.$name); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | 'last_modified' => $this->getLastModified(), |
| 184 | 184 | 'metrics' => array(), |
| 185 | 185 | 'name' => $this->getName(), |
| 186 | - 'schedule' => $this->getSchedule()?$this->getSchedule()->toArray():null, |
|
| 186 | + 'schedule' => $this->getSchedule() ? $this->getSchedule()->toArray() : null, |
|
| 187 | 187 | 'status' => $this->getStatus(), |
| 188 | 188 | 'variations' => array(), |
| 189 | 189 | 'id' => $this->getId(), |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | // Remove options with empty values |
| 206 | 206 | $cleanedOptions = array(); |
| 207 | 207 | foreach ($options as $name=>$value) { |
| 208 | - if ($value!==null) |
|
| 208 | + if ($value !== null) |
|
| 209 | 209 | $cleanedOptions[$name] = $value; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -51,8 +51,9 @@ |
||
| 51 | 51 | // Remove options with empty values |
| 52 | 52 | $cleanedOptions = array(); |
| 53 | 53 | foreach ($options as $name=>$value) { |
| 54 | - if ($value!==null) |
|
| 55 | - $cleanedOptions[$name] = $value; |
|
| 54 | + if ($value!==null) { |
|
| 55 | + $cleanedOptions[$name] = $value; |
|
| 56 | + } |
|
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | return $cleanedOptions; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | case 'is_classic': $this->setIsClassic($value); break; |
| 125 | 125 | case 'is_editable': $this->setIsEditable($value); break; |
| 126 | 126 | default: |
| 127 | - throw new Exception('Unknown option: ' . $name); |
|
| 127 | + throw new Exception('Unknown option: '.$name); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | 'category' => $this->getCategory(), |
| 141 | 141 | 'created' => $this->getCreated(), |
| 142 | 142 | 'description' => $this->getDescription(), |
| 143 | - 'event_filter' => $this->getEventFilter()?$this->getEventFilter()->toArray():null, |
|
| 143 | + 'event_filter' => $this->getEventFilter() ? $this->getEventFilter()->toArray() : null, |
|
| 144 | 144 | 'event_type' => $this->getEventType(), |
| 145 | 145 | 'key' => $this->getKey(), |
| 146 | 146 | 'name' => $this->getName(), |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | // Remove options with empty values |
| 155 | 155 | $cleanedOptions = array(); |
| 156 | 156 | foreach ($options as $name=>$value) { |
| 157 | - if ($value!==null) |
|
| 157 | + if ($value !== null) |
|
| 158 | 158 | $cleanedOptions[$name] = $value; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -51,8 +51,9 @@ |
||
| 51 | 51 | // Remove options with empty values |
| 52 | 52 | $cleanedOptions = array(); |
| 53 | 53 | foreach ($options as $name=>$value) { |
| 54 | - if ($value!==null) |
|
| 55 | - $cleanedOptions[$name] = $value; |
|
| 54 | + if ($value!==null) { |
|
| 55 | + $cleanedOptions[$name] = $value; |
|
| 56 | + } |
|
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | return $cleanedOptions; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | case 'value': $this->setValue($value); break; |
| 89 | 89 | case 'variation_id': $this->setVariationId($value); break; |
| 90 | 90 | default: |
| 91 | - throw new Exception('Unknown option: ' . $name); |
|
| 91 | + throw new Exception('Unknown option: '.$name); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -101,11 +101,11 @@ discard block |
||
| 101 | 101 | $options = array( |
| 102 | 102 | 'experiment_id' => $this->getExperimentId(), |
| 103 | 103 | 'is_baseline' => $this->getIsBaseline(), |
| 104 | - 'lift' => $this->getLift()?$this->getLift()->toArray():null, |
|
| 104 | + 'lift' => $this->getLift() ? $this->getLift()->toArray() : null, |
|
| 105 | 105 | 'name' => $this->getName(), |
| 106 | 106 | 'rate' => $this->getRate(), |
| 107 | 107 | 'scope' => $this->getScope(), |
| 108 | - 'total_increase' => $this->getTotalIncrease()?$this->getTotalIncrease()->toArray():null, |
|
| 108 | + 'total_increase' => $this->getTotalIncrease() ? $this->getTotalIncrease()->toArray() : null, |
|
| 109 | 109 | 'value' => $this->getValue(), |
| 110 | 110 | 'variation_id' => $this->getVariationId() |
| 111 | 111 | ); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | // Remove options with empty values |
| 114 | 114 | $cleanedOptions = array(); |
| 115 | 115 | foreach ($options as $name=>$value) { |
| 116 | - if ($value!==null) |
|
| 116 | + if ($value !== null) |
|
| 117 | 117 | $cleanedOptions[$name] = $value; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -51,8 +51,9 @@ |
||
| 51 | 51 | // Remove options with empty values |
| 52 | 52 | $cleanedOptions = array(); |
| 53 | 53 | foreach ($options as $name=>$value) { |
| 54 | - if ($value!==null) |
|
| 55 | - $cleanedOptions[$name] = $value; |
|
| 54 | + if ($value!==null) { |
|
| 55 | + $cleanedOptions[$name] = $value; |
|
| 56 | + } |
|
| 56 | 57 | } |
| 57 | 58 | |
| 58 | 59 | return $cleanedOptions; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | case 'variation_id': $this->setVariationId($value); break; |
| 50 | 50 | case 'variation_reach': $this->setVariationReach($value); break; |
| 51 | 51 | default: |
| 52 | - throw new Exception('Unknown option: ' . $name); |
|
| 52 | + throw new Exception('Unknown option: '.$name); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | // Remove options with empty values |
| 70 | 70 | $cleanedOptions = array(); |
| 71 | 71 | foreach ($options as $name=>$value) { |
| 72 | - if ($value!==null) |
|
| 72 | + if ($value !== null) |
|
| 73 | 73 | $cleanedOptions[$name] = $value; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -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,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 | |
@@ -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() |
@@ -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 |
@@ -56,8 +56,9 @@ |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Determine if there are more projects. |
| 59 | - if ($result->getNextPage()==null) |
|
| 60 | - break; |
|
| 59 | + if ($result->getNextPage()==null) { |
|
| 60 | + break; |
|
| 61 | + } |
|
| 61 | 62 | |
| 62 | 63 | // Increment page counter. |
| 63 | 64 | $page ++; |
@@ -56,8 +56,9 @@ |
||
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Determine if there are more projects. |
| 59 | - if ($result->getNextPage()==null) |
|
| 60 | - break; |
|
| 59 | + if ($result->getNextPage()==null) { |
|
| 60 | + break; |
|
| 61 | + } |
|
| 61 | 62 | |
| 62 | 63 | // Increment page counter. |
| 63 | 64 | $page ++; |
@@ -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: " . $experiment->getStatus() . "\n"; |
|
| 53 | - echo "Created: " . $experiment->getCreated() . "\n"; |
|
| 50 | + echo "Name: ".$experiment->getName()."\n"; |
|
| 51 | + echo "Description: ".$experiment->getDescription()."\n"; |
|
| 52 | + echo "Status: ".$experiment->getStatus()."\n"; |
|
| 53 | + echo "Created: ".$experiment->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"; |