@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @return array |
| 39 | 39 | * @throws \Exception |
| 40 | 40 | */ |
| 41 | - public function listAll($projectId, $campaignId=null, $includeClassic=false, $page=1, $perPage=10) |
|
| 41 | + public function listAll($projectId, $campaignId = null, $includeClassic = false, $page = 1, $perPage = 10) |
|
| 42 | 42 | { |
| 43 | 43 | if (empty($projectId) && empty($campaignId)) { |
| 44 | 44 | throw new \Exception('Project ID or Campaign ID must be non-empty'); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | throw new \Exception("Expected argument of type Experiment"); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if ($experimentId<0) { |
|
| 151 | + if ($experimentId < 0) { |
|
| 152 | 152 | throw new \Exception("Expected positive experiment ID argument"); |
| 153 | 153 | } |
| 154 | 154 | |
@@ -38,13 +38,13 @@ |
||
| 38 | 38 | * @return array[Event] |
| 39 | 39 | * @throws \Exception |
| 40 | 40 | */ |
| 41 | - public function listAll($projectId, $includeClassic, $page=0, $perPage=10) |
|
| 41 | + public function listAll($projectId, $includeClassic, $page = 0, $perPage = 10) |
|
| 42 | 42 | { |
| 43 | - if ($page<0) { |
|
| 43 | + if ($page < 0) { |
|
| 44 | 44 | throw new \Exception('Invalid page number passed'); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - if ($perPage<0) { |
|
| 47 | + if ($perPage < 0) { |
|
| 48 | 48 | throw new \Exception('Invalid page size passed'); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | * @return array |
| 35 | 35 | * @throws \Exception |
| 36 | 36 | */ |
| 37 | - public function listAll($page=0, $perPage=10) |
|
| 37 | + public function listAll($page = 0, $perPage = 10) |
|
| 38 | 38 | { |
| 39 | - if ($page<0) { |
|
| 39 | + if ($page < 0) { |
|
| 40 | 40 | throw new \Exception('Invalid page number passed'); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if ($perPage<0 || $perPage>100) { |
|
| 43 | + if ($perPage < 0 || $perPage > 100) { |
|
| 44 | 44 | throw new \Exception('Invalid page size passed'); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | throw new \Exception("Integer project ID expected, while got '$projectId'"); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ($projectId<0) { |
|
| 74 | + if ($projectId < 0) { |
|
| 75 | 75 | throw new \Exception("A positive project ID expected"); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | throw new \Exception("Integer project ID expected, while got '$projectId'"); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if ($projectId<0) { |
|
| 119 | + if ($projectId < 0) { |
|
| 120 | 120 | throw new \Exception("A positive project ID expected"); |
| 121 | 121 | } |
| 122 | 122 | |
@@ -36,21 +36,21 @@ discard block |
||
| 36 | 36 | * @return array[Campaign] |
| 37 | 37 | * @throws \Exception |
| 38 | 38 | */ |
| 39 | - public function listAll($projectId, $page=0, $perPage=10) |
|
| 39 | + public function listAll($projectId, $page = 0, $perPage = 10) |
|
| 40 | 40 | { |
| 41 | 41 | if (!is_int($projectId)) { |
| 42 | 42 | throw new \Exception("Integer project ID expected, while got '$projectId'"); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if ($projectId<0) { |
|
| 45 | + if ($projectId < 0) { |
|
| 46 | 46 | throw new \Exception("Expected positive integer project ID"); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ($page<0) { |
|
| 49 | + if ($page < 0) { |
|
| 50 | 50 | throw new \Exception('Invalid page number passed'); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - if ($perPage<0) { |
|
| 53 | + if ($perPage < 0) { |
|
| 54 | 54 | throw new \Exception('Invalid page size passed'); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | throw new \Exception("Integer campaign ID expected, while got '$campaignId'"); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if ($campaignId<0) { |
|
| 105 | + if ($campaignId < 0) { |
|
| 106 | 106 | throw new \Exception("Expected positive integer campaign ID"); |
| 107 | 107 | } |
| 108 | 108 | |
@@ -35,13 +35,13 @@ |
||
| 35 | 35 | * @return array[Audience] |
| 36 | 36 | * @throws \Exception |
| 37 | 37 | */ |
| 38 | - public function listAll($projectId, $page=0, $perPage=10) |
|
| 38 | + public function listAll($projectId, $page = 0, $perPage = 10) |
|
| 39 | 39 | { |
| 40 | - if ($page<0) { |
|
| 40 | + if ($page < 0) { |
|
| 41 | 41 | throw new \Exception('Invalid page number passed'); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if ($perPage<0) { |
|
| 44 | + if ($perPage < 0) { |
|
| 45 | 45 | throw new \Exception('Invalid page size passed'); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -41,13 +41,13 @@ discard block |
||
| 41 | 41 | * @param string $authCredentials Auth credentials. |
| 42 | 42 | * @param string $apiVersion Optional. Currently supported 'v2' only. |
| 43 | 43 | */ |
| 44 | - public function __construct($authCredentials, $apiVersion='v2') |
|
| 44 | + public function __construct($authCredentials, $apiVersion = 'v2') |
|
| 45 | 45 | { |
| 46 | 46 | if (!is_array($authCredentials)) { |
| 47 | 47 | throw new \Exception('Auth credentials must be an array'); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if ($apiVersion!='v2') { |
|
| 50 | + if ($apiVersion != 'v2') { |
|
| 51 | 51 | throw new \Exception('Invalid API version passed'); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function setApiVersion($apiVersion) |
| 76 | 76 | { |
| 77 | - if ($apiVersion!='v2') { |
|
| 77 | + if ($apiVersion != 'v2') { |
|
| 78 | 78 | throw new \Exception('Invalid API version passed'); |
| 79 | 79 | } |
| 80 | 80 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | public function setAuthCredentials($authCredentials) |
| 98 | 98 | { |
| 99 | - if (!is_array($authCredentials) || count($authCredentials)==0) { |
|
| 99 | + if (!is_array($authCredentials) || count($authCredentials) == 0) { |
|
| 100 | 100 | throw new \Exception('Auth credentials must be an array'); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | * @return array Optimizely response in form of array. |
| 157 | 157 | * @throws \Exception |
| 158 | 158 | */ |
| 159 | - public function sendApiRequest($url, $queryParams = array(), $method='GET', |
|
| 159 | + public function sendApiRequest($url, $queryParams = array(), $method = 'GET', |
|
| 160 | 160 | $postData = array(), $expectedResponseCodes = array(200)) |
| 161 | 161 | { |
| 162 | 162 | // If access token has expired, try to get another one with refresh token. |
| 163 | - if ($this->isAccessTokenExpired() && $this->getRefreshToken()!=null) { |
|
| 163 | + if ($this->isAccessTokenExpired() && $this->getRefreshToken() != null) { |
|
| 164 | 164 | $this->getAccessTokenByRefreshToken(); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Produce absolute URL |
| 168 | - $url = 'https://api.optimizely.com/' . $this->apiVersion . $url; |
|
| 168 | + $url = 'https://api.optimizely.com/'.$this->apiVersion.$url; |
|
| 169 | 169 | |
| 170 | 170 | $result = $this->sendHttpRequest($url, $queryParams, $method, |
| 171 | 171 | $postData, $expectedResponseCodes); |
@@ -183,45 +183,45 @@ discard block |
||
| 183 | 183 | * @return array Optimizely response in form of array. |
| 184 | 184 | * @throws \Exception |
| 185 | 185 | */ |
| 186 | - private function sendHttpRequest($url, $queryParams = array(), $method='GET', |
|
| 186 | + private function sendHttpRequest($url, $queryParams = array(), $method = 'GET', |
|
| 187 | 187 | $postData = array(), $expectedResponseCodes = array(200)) |
| 188 | 188 | { |
| 189 | 189 | // Check if CURL is initialized (it should have been initialized in |
| 190 | 190 | // constructor). |
| 191 | - if ($this->curlHandle==false) { |
|
| 191 | + if ($this->curlHandle == false) { |
|
| 192 | 192 | throw new \Exception('CURL is not initialized', -1); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if ($method!='GET' && $method!='POST' && $method!='PUT' && |
|
| 196 | - $method!='PATCH' && $method!='DELETE') { |
|
| 197 | - throw new \Exception('Invalid HTTP method passed: ' . $method, -1); |
|
| 195 | + if ($method != 'GET' && $method != 'POST' && $method != 'PUT' && |
|
| 196 | + $method != 'PATCH' && $method != 'DELETE') { |
|
| 197 | + throw new \Exception('Invalid HTTP method passed: '.$method, -1); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | if (!isset($this->authCredentials['access_token'])) { |
| 201 | - throw new \Exception('OAuth access token is not set. You should pass ' . |
|
| 201 | + throw new \Exception('OAuth access token is not set. You should pass '. |
|
| 202 | 202 | 'it to the class constructor when initializing the Optimizely client.', -1); |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // Append query parameters to URL. |
| 206 | - if (count($queryParams)!=0) { |
|
| 206 | + if (count($queryParams) != 0) { |
|
| 207 | 207 | $query = http_build_query($queryParams); |
| 208 | - $url .= '?' . $query; |
|
| 208 | + $url .= '?'.$query; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | $headers = array( |
| 212 | - "Authorization: Bearer " . $this->authCredentials['access_token'], |
|
| 212 | + "Authorization: Bearer ".$this->authCredentials['access_token'], |
|
| 213 | 213 | "Content-Type: application/json" |
| 214 | 214 | ); |
| 215 | 215 | $content = ''; |
| 216 | - if (count($postData)!=0) { |
|
| 216 | + if (count($postData) != 0) { |
|
| 217 | 217 | $content = json_encode($postData); |
| 218 | 218 | } |
| 219 | - $headers[] = "Content-length:" . strlen($content); |
|
| 219 | + $headers[] = "Content-length:".strlen($content); |
|
| 220 | 220 | |
| 221 | 221 | // Set HTTP options. |
| 222 | 222 | curl_setopt($this->curlHandle, CURLOPT_URL, $url); |
| 223 | 223 | curl_setopt($this->curlHandle, CURLOPT_CUSTOMREQUEST, $method); |
| 224 | - if (count($postData)!=0) { |
|
| 224 | + if (count($postData) != 0) { |
|
| 225 | 225 | curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, $content); |
| 226 | 226 | } |
| 227 | 227 | curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true); |
@@ -239,16 +239,16 @@ discard block |
||
| 239 | 239 | // Check HTTP response code. |
| 240 | 240 | $info = curl_getinfo($this->curlHandle); |
| 241 | 241 | if (!in_array($info['http_code'], $expectedResponseCodes)) { |
| 242 | - throw new \Exception('Unexpected HTTP response code: ' . $info['http_code'] . |
|
| 243 | - '. Request was ' . $method . ' "' . $url . '". Response was "' . $result . '"', |
|
| 242 | + throw new \Exception('Unexpected HTTP response code: '.$info['http_code']. |
|
| 243 | + '. Request was '.$method.' "'.$url.'". Response was "'.$result.'"', |
|
| 244 | 244 | $info['http_code']); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // JSON-decode response. |
| 248 | 248 | $decodedResult = json_decode($result, true); |
| 249 | 249 | if (!is_array($decodedResult)) { |
| 250 | - throw new \Exception('Could not JSON-decode the Optimizely response. Request was ' . |
|
| 251 | - $method . ' "' . $url . '". The response was: "' . $result . '"', |
|
| 250 | + throw new \Exception('Could not JSON-decode the Optimizely response. Request was '. |
|
| 251 | + $method.' "'.$url.'". The response was: "'.$result.'"', |
|
| 252 | 252 | $info['http_code']); |
| 253 | 253 | } |
| 254 | 254 | |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | private function isAccessTokenExpired() |
| 265 | 265 | { |
| 266 | - if(!isset($this->authCredentials['access_token'])) { |
|
| 266 | + if (!isset($this->authCredentials['access_token'])) { |
|
| 267 | 267 | return true; // We do not have access token. |
| 268 | 268 | } |
| 269 | 269 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | $response = $this->sendHttpRequest($url, array(), 'POST'); |
| 308 | 308 | |
| 309 | 309 | if (!isset($response['access_token'])) { |
| 310 | - throw new \Exception('Not found access token in response. Request URL was "' . $url. '". Response was "' . print_r($response, true). '"'); |
|
| 310 | + throw new \Exception('Not found access token in response. Request URL was "'.$url.'". Response was "'.print_r($response, true).'"'); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | $this->authCredentials['access_token'] = $response['access_token']; |
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | case 'unit': $this->setUnit($value); break; |
| 73 | 73 | case 'variation_results': $this->setVariationResults($value); break; |
| 74 | 74 | default: |
| 75 | - throw new \Exception('Unknown option: ' . $name); |
|
| 75 | + throw new \Exception('Unknown option: '.$name); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | case 'value': $this->setValue($value); break; |
| 88 | 88 | case 'variation_id': $this->setVariationId($value); break; |
| 89 | 89 | default: |
| 90 | - throw new \Exception('Unknown option: ' . $name); |
|
| 90 | + throw new \Exception('Unknown option: '.$name); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | $options = array( |
| 101 | 101 | 'experiment_id' => $this->getExperimentId(), |
| 102 | 102 | 'is_baseline' => $this->getIsBaseline(), |
| 103 | - 'lift' => $this->getLift()?$this->getLift()->toArray():null, |
|
| 103 | + 'lift' => $this->getLift() ? $this->getLift()->toArray() : null, |
|
| 104 | 104 | 'name' => $this->getName(), |
| 105 | 105 | 'rate' => $this->getRate(), |
| 106 | 106 | 'scope' => $this->getScope(), |
| 107 | - 'total_increase' => $this->getTotalIncrease()?$this->getTotalIncrease()->toArray():null, |
|
| 107 | + 'total_increase' => $this->getTotalIncrease() ? $this->getTotalIncrease()->toArray() : null, |
|
| 108 | 108 | 'value' => $this->getValue(), |
| 109 | 109 | 'variation_id' => $this->getVariationId() |
| 110 | 110 | ); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | // Remove options with empty values |
| 113 | 113 | $cleanedOptions = array(); |
| 114 | 114 | foreach ($options as $name=>$value) { |
| 115 | - if ($value!==null) |
|
| 115 | + if ($value !== null) |
|
| 116 | 116 | $cleanedOptions[$name] = $value; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | case 'is_classic': $this->setIsClassic($value); break; |
| 124 | 124 | case 'is_editable': $this->setIsEditable($value); break; |
| 125 | 125 | default: |
| 126 | - throw new \Exception('Unknown option: ' . $name); |
|
| 126 | + throw new \Exception('Unknown option: '.$name); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | 'category' => $this->getCategory(), |
| 140 | 140 | 'created' => $this->getCreated(), |
| 141 | 141 | 'description' => $this->getDescription(), |
| 142 | - 'event_filter' => $this->getEventFilter()?$this->getEventFilter()->toArray():null, |
|
| 142 | + 'event_filter' => $this->getEventFilter() ? $this->getEventFilter()->toArray() : null, |
|
| 143 | 143 | 'event_type' => $this->getEventType(), |
| 144 | 144 | 'key' => $this->getKey(), |
| 145 | 145 | 'name' => $this->getName(), |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | // Remove options with empty values |
| 154 | 154 | $cleanedOptions = array(); |
| 155 | 155 | foreach ($options as $name=>$value) { |
| 156 | - if ($value!==null) |
|
| 156 | + if ($value !== null) |
|
| 157 | 157 | $cleanedOptions[$name] = $value; |
| 158 | 158 | } |
| 159 | 159 | |