Completed
Push — develop ( 36e9ea...2b118d )
by Oleg
10:59 queued 02:24
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[Page]
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
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.
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 array $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
         
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function setApiVersion($apiVersion)
77 77
     {
78
-        if ($apiVersion!='v2') {
78
+        if ($apiVersion != 'v2') {
79 79
             throw new \Exception('Invalid API version passed');
80 80
         }
81 81
         
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      */
98 98
     public function setAuthCredentials($authCredentials)
99 99
     {
100
-        if (!is_array($authCredentials) || count($authCredentials)==0) {
100
+        if (!is_array($authCredentials) || count($authCredentials) == 0) {
101 101
             throw new \Exception('Auth credentials must be an array');            
102 102
         }
103 103
         
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
      * @return array Optimizely response in form of array.
158 158
      * @throws \Exception
159 159
      */
160
-    public function sendApiRequest($url, $queryParams = array(), $method='GET', 
160
+    public function sendApiRequest($url, $queryParams = array(), $method = 'GET', 
161 161
             $postData = array(), $expectedResponseCodes = array(200))
162 162
     {
163 163
         // If access token has expired, try to get another one with refresh token.
164
-        if ($this->isAccessTokenExpired() && $this->getRefreshToken()!=null) {
164
+        if ($this->isAccessTokenExpired() && $this->getRefreshToken() != null) {
165 165
             $this->getAccessTokenByRefreshToken();
166 166
         }
167 167
         
168 168
         // Produce absolute URL
169
-        $url = 'https://api.optimizely.com/' . $this->apiVersion . $url;
169
+        $url = 'https://api.optimizely.com/'.$this->apiVersion.$url;
170 170
         
171 171
         $result = $this->sendHttpRequest($url, $queryParams, $method, 
172 172
                 $postData, $expectedResponseCodes);
@@ -184,45 +184,45 @@  discard block
 block discarded – undo
184 184
      * @return array Optimizely response in form of array.
185 185
      * @throws \Exception
186 186
      */
187
-    private function sendHttpRequest($url, $queryParams = array(), $method='GET', 
187
+    private function sendHttpRequest($url, $queryParams = array(), $method = 'GET', 
188 188
             $postData = array(), $expectedResponseCodes = array(200))
189 189
     {
190 190
         // Check if CURL is initialized (it should have been initialized in 
191 191
         // constructor).
192
-        if ($this->curlHandle==false) {
192
+        if ($this->curlHandle == false) {
193 193
             throw new \Exception('CURL is not initialized', -1);
194 194
         }
195 195
         
196
-        if ($method!='GET' && $method!='POST' && $method!='PUT' && 
197
-            $method!='PATCH' && $method!='DELETE') {
198
-            throw new \Exception('Invalid HTTP method passed: ' . $method, -1);
196
+        if ($method != 'GET' && $method != 'POST' && $method != 'PUT' && 
197
+            $method != 'PATCH' && $method != 'DELETE') {
198
+            throw new \Exception('Invalid HTTP method passed: '.$method, -1);
199 199
         }
200 200
         
201 201
         if (!isset($this->authCredentials['access_token'])) {
202
-            throw new \Exception('OAuth access token is not set. You should pass ' . 
202
+            throw new \Exception('OAuth access token is not set. You should pass '. 
203 203
                     'it to the class constructor when initializing the Optimizely client.', -1);
204 204
         }
205 205
                 
206 206
         // Append query parameters to URL.
207
-        if (count($queryParams)!=0) {            
207
+        if (count($queryParams) != 0) {            
208 208
             $query = http_build_query($queryParams);
209
-            $url .= '?' . $query;
209
+            $url .= '?'.$query;
210 210
         }
211 211
         
212 212
         $headers = array(
213
-            "Authorization: Bearer " . $this->authCredentials['access_token'],
213
+            "Authorization: Bearer ".$this->authCredentials['access_token'],
214 214
             "Content-Type: application/json"
215 215
             );
216 216
         $content = '';
217
-        if (count($postData)!=0) {
217
+        if (count($postData) != 0) {
218 218
             $content = json_encode($postData);            
219 219
         }
220
-        $headers[] = "Content-length:" . strlen($content);            
220
+        $headers[] = "Content-length:".strlen($content);            
221 221
         
222 222
         // Set HTTP options.
223 223
         curl_setopt($this->curlHandle, CURLOPT_URL, $url);
224 224
         curl_setopt($this->curlHandle, CURLOPT_CUSTOMREQUEST, $method);        
225
-        if (count($postData)!=0) {
225
+        if (count($postData) != 0) {
226 226
             curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, $content);            
227 227
         }
228 228
         curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, true);
@@ -240,16 +240,16 @@  discard block
 block discarded – undo
240 240
         // Check HTTP response code.
241 241
         $info = curl_getinfo($this->curlHandle);
242 242
         if (!in_array($info['http_code'], $expectedResponseCodes)) {
243
-            throw new \Exception('Unexpected HTTP response code: ' . $info['http_code'] . 
244
-                    '. Request was ' . $method . ' "' . $url . '". Response was "' . $result . '"',
243
+            throw new \Exception('Unexpected HTTP response code: '.$info['http_code']. 
244
+                    '. Request was '.$method.' "'.$url.'". Response was "'.$result.'"',
245 245
                     $info['http_code']);
246 246
         }
247 247
         
248 248
         // JSON-decode response.
249 249
         $decodedResult = json_decode($result, true);
250 250
         if (!is_array($decodedResult)) {
251
-            throw new \Exception('Could not JSON-decode the Optimizely response. Request was ' . 
252
-                    $method . ' "' . $url . '". The response was: "' . $result . '"',
251
+            throw new \Exception('Could not JSON-decode the Optimizely response. Request was '. 
252
+                    $method.' "'.$url.'". The response was: "'.$result.'"',
253 253
                     $info['http_code']);
254 254
         }
255 255
         
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      */
265 265
     private function isAccessTokenExpired() 
266 266
     {
267
-        if(!isset($this->authCredentials['access_token'])) {
267
+        if (!isset($this->authCredentials['access_token'])) {
268 268
             return true; // We do not have access token.
269 269
         }
270 270
         
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         $response = $this->sendHttpRequest($url, array(), 'POST');
310 310
         
311 311
         if (!isset($response['access_token'])) {
312
-            throw new \Exception('Not found access token in response. Request URL was "' . $url. '". Response was "' . print_r($response, true). '"');
312
+            throw new \Exception('Not found access token in response. Request URL was "'.$url.'". Response was "'.print_r($response, true).'"');
313 313
         }
314 314
         
315 315
         $this->authCredentials['access_token'] = $response['access_token'];
Please login to merge, or discard this patch.
lib/WebMarketingROI/OptimizelyPHP/Resource/v2/CampaignResults.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                 }
67 67
                 case 'start_time': $this->setStartTime($value); break;
68 68
                 default:
69
-                    throw new \Exception('Unknown option: ' . $name);
69
+                    throw new \Exception('Unknown option: '.$name);
70 70
             }
71 71
         }
72 72
     }
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
         // Remove options with empty values
92 92
         $cleanedOptions = array();
93 93
         foreach ($options as $name=>$value) {
94
-            if ($value!==null)
94
+            if ($value !== null)
95 95
                 $cleanedOptions[$name] = $value;
96 96
         }
97 97
         
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.