Completed
Push — master ( b0aab6...90835e )
by James
02:41
created
examples/Experiments/CreateExperiment.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,6 @@
 block discarded – undo
13 13
  */
14 14
 
15 15
 use WebMarketingROI\OptimizelyPHP\OptimizelyApiClient;
16
-use WebMarketingROI\OptimizelyPHP\Resource\v2\Project;
17 16
 
18 17
 // Init class autloading.
19 18
 include dirname(__FILE__) . '/../../vendor/autoload.php';
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -32,73 +32,73 @@
 block discarded – undo
32 32
     $project = new Experiment(array(
33 33
             "project_id" => 1000,
34 34
             "audience_ids" => array(
35
-              1234,
36
-              1212,
37
-              1432
35
+                1234,
36
+                1212,
37
+                1432
38 38
             ),
39 39
             "campaign_id" => 2000,
40 40
             "changes" => array(
41
-              array(
41
+                array(
42 42
                 "type" => "custom_code",
43 43
                 "allow_additional_redirect" => true,
44 44
                 "async" => true,
45 45
                 "css_selector" => "a[href*=\"optimizely\"]",
46 46
                 "dependencies" => array(
47
-                  24,
48
-                  26
47
+                    24,
48
+                    26
49 49
                 ),
50 50
                 "destination" => "https://app.optimizely.com/",
51 51
                 "extension_id" => 1234,
52 52
                 "preserve_parameters" => true,
53 53
                 "src" => 524,
54 54
                 "value" => "window.someGlobalFunction();"
55
-              )
55
+                )
56 56
             ),
57 57
             "description" => "string",
58 58
             "holdback" => 5000,
59 59
             "key" => "home_page_experiment",
60 60
             "metrics" => array(
61
-              array(
61
+                array(
62 62
                 "kind" => "string"
63
-              )
63
+                )
64 64
             ),
65 65
             "name" => "Blue Button Experiment",
66 66
             "schedule" => array(
67
-              "start_time" => "2016-10-17T07:04:59.724Z",
68
-              "stop_time" => "2016-10-17T07:04:59.724Z",
69
-              "time_zone" => "UTC"
67
+                "start_time" => "2016-10-17T07:04:59.724Z",
68
+                "stop_time" => "2016-10-17T07:04:59.724Z",
69
+                "time_zone" => "UTC"
70 70
             ),
71 71
             "status" => "active",
72 72
             "variations" => array(
73
-              array(
73
+                array(
74 74
                 "actions" => array(
75
-                  array(
75
+                    array(
76 76
                     "changes" => array(
77
-                      array(
77
+                        array(
78 78
                         "type" => "custom_code",
79 79
                         "allow_additional_redirect" => true,
80 80
                         "async" => true,
81 81
                         "css_selector" => "a[href*=\"optimizely\"]",
82 82
                         "dependencies" => array(
83
-                          24,
84
-                          26
83
+                            24,
84
+                            26
85 85
                         ),
86 86
                         "destination" => "https://app.optimizely.com/",
87 87
                         "extension_id" => 1234,
88 88
                         "preserve_parameters" => true,
89 89
                         "src" => 524,
90 90
                         "value" => "window.someGlobalFunction();"
91
-                      )
91
+                        )
92 92
                     ),
93 93
                     "page_id" => 0
94
-                  )
94
+                    )
95 95
                 ),
96 96
                 "archived" => true,
97 97
                 "key" => "blue_button_variation",
98 98
                 "name" => "Blue Button",
99 99
                 "variation_id" => 0,
100 100
                 "weight" => 0
101
-              )
101
+                )
102 102
             )
103 103
         ));
104 104
         
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@  discard block
 block discarded – undo
16 16
 use WebMarketingROI\OptimizelyPHP\Resource\v2\Project;
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();
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
     $createdExperiment = $optimizelyClient->experiments()->create($experiment);
106 106
                 
107 107
 } catch (\Exception $e) {
108
-    echo "Exception caught: " . $e->getMessage() . "\n";    
108
+    echo "Exception caught: ".$e->getMessage()."\n";    
109 109
 }    
110 110
 
111 111
 // Save access token for later use
112 112
 $accessToken = $optimizelyClient->getAccessToken();
113
-file_put_contents(dirname(__FILE__) . '/../access_token.json', json_encode($accessToken));
113
+file_put_contents(dirname(__FILE__).'/../access_token.json', json_encode($accessToken));
114 114
 
115 115
 echo "Done!\n";
116 116
\ No newline at end of file
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Audiences.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@
 block discarded – undo
63 63
     
64 64
     /**
65 65
      * Get metadata for a single Audience.
66
-     * @param type $audienceId
66
+     * @param integer $audienceId
67 67
      * @return Audience
68 68
      * @throws \Exception
69 69
      */
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,13 +35,13 @@
 block discarded – undo
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
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Campaigns.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@
 block discarded – undo
92 92
     /**
93 93
      * Get campaign results
94 94
      * @param integer $campaignId The id for the campaign you want results for
95
-     * @param string $starTime The earliest time to count events in results. Defaults to the time that the campaign was first activated.
95
+     * @param string $startTime The earliest time to count events in results. Defaults to the time that the campaign was first activated.
96 96
      * @param string $endTime The latest time to count events in results. Defaults to the time the campaign was last active or the current time if the campaign is still running.
97 97
      * @throws \Exception
98 98
      */
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,21 +36,21 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Events.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
     
68 68
     /**
69 69
      * Get Event by ID
70
-     * @param type $eventId
70
+     * @param integer $eventId
71 71
      * @return Event
72 72
      * @throws \Exception
73 73
      */
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -38,13 +38,13 @@
 block discarded – undo
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
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Pages.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@
 block discarded – undo
101 101
     /**
102 102
      * Update a Page in a provided Project
103 103
      * @param integer $pageId
104
-     * @param Audience $page
104
+     * @param Page $page
105 105
      * @throws \Exception
106 106
      */
107 107
     public function update($pageId, $page) 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,13 +35,13 @@
 block discarded – undo
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
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Experiments.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Service/v2/Projects.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/OptimizelyApiClient.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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'];
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -289,14 +289,17 @@
 block discarded – undo
289 289
      */
290 290
     private function getAccessTokenByRefreshToken()
291 291
     {
292
-        if (!isset($this->authCredentials['client_id']))
293
-            throw new \Exception('OAuth 2.0 client ID is not set');
292
+        if (!isset($this->authCredentials['client_id'])) {
293
+                    throw new \Exception('OAuth 2.0 client ID is not set');
294
+        }
294 295
         
295
-        if (!isset($this->authCredentials['client_secret']))
296
-            throw new \Exception('OAuth 2.0 client secret is not set');
296
+        if (!isset($this->authCredentials['client_secret'])) {
297
+                    throw new \Exception('OAuth 2.0 client secret is not set');
298
+        }
297 299
         
298
-        if (!isset($this->authCredentials['refresh_token']))
299
-            throw new \Exception('Refresh token is not set');
300
+        if (!isset($this->authCredentials['refresh_token'])) {
301
+                    throw new \Exception('Refresh token is not set');
302
+        }
300 303
         
301 304
         $clientId = $this->authCredentials['client_id'];
302 305
         $clientSecret = $this->authCredentials['client_secret'];
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Resource/v2/ExperimentMetricResults.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.