Completed
Branch master (8b4054)
by Zhmayev
01:23
created
src/Session.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         $postdata = [
100 100
             'operation' => 'login',
101 101
             'username'  => $username,
102
-            'accessKey' => md5($this->serviceToken . $accessKey)
102
+            'accessKey' => md5($this->serviceToken.$accessKey)
103 103
         ];
104 104
 
105 105
         $result = $this->sendHttpRequest($postdata);
@@ -112,12 +112,12 @@  discard block
 block discarded – undo
112 112
         $this->accessKey = $accessKey;
113 113
 
114 114
         // Session data
115
-        $this->sessionName = $result['sessionName'];
116
-        $this->userID = $result['userId'];
115
+        $this->sessionName = $result[ 'sessionName' ];
116
+        $this->userID = $result[ 'userId' ];
117 117
 
118 118
         // Vtiger CRM and WebServices API version
119
-        $this->vtigerApiVersion = $result['version'];
120
-        $this->vtigerVersion = $result['vtigerVersion'];
119
+        $this->vtigerApiVersion = $result[ 'version' ];
120
+        $this->vtigerVersion = $result[ 'vtigerVersion' ];
121 121
 
122 122
         return true;
123 123
     }
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
         }
150 150
 
151 151
         $this->accessKey = array_key_exists('accesskey', $result)
152
-            ? $result['accesskey']
153
-            : $result[0];
152
+            ? $result[ 'accesskey' ]
153
+            : $result[ 0 ];
154 154
 
155 155
         return $this->login($username, $accessKey);
156 156
     }
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
         ];
170 170
         $result = $this->sendHttpRequest($getdata, 'GET');
171 171
         
172
-        if (!is_array($result) || !isset($result['token'])) {
172
+        if (!is_array($result) || !isset($result[ 'token' ])) {
173 173
             return false;
174 174
         }
175 175
 
176
-        $this->serviceExpireTime = $result['expireTime'];
177
-        $this->serviceToken = $result['token'];
176
+        $this->serviceExpireTime = $result[ 'expireTime' ];
177
+        $this->serviceToken = $result[ 'token' ];
178 178
 
179 179
         return true;
180 180
     }
@@ -222,30 +222,30 @@  discard block
 block discarded – undo
222 222
      */
223 223
     public function sendHttpRequest(array $requestData, $method = 'POST')
224 224
     {
225
-        if (!isset($requestData['operation'])) {
225
+        if (!isset($requestData[ 'operation' ])) {
226 226
             throw new WSException('Request data must contain the name of the operation!');
227 227
         }
228 228
 
229
-        $requestData['sessionName'] = $this->sessionName;
229
+        $requestData[ 'sessionName' ] = $this->sessionName;
230 230
 
231 231
         // Perform re-login if required.
232
-        if ('getchallenge' !== $requestData['operation'] && time() > $this->serviceExpireTime) {
232
+        if ('getchallenge' !== $requestData[ 'operation' ] && time() > $this->serviceExpireTime) {
233 233
             $this->login($this->userName, $this->accessKey);
234 234
         }
235 235
         
236 236
         try {
237 237
             switch ($method) {
238 238
                 case 'GET':
239
-                    $response = $this->httpClient->get($this->serviceBaseURL, ['query' => $requestData]);
239
+                    $response = $this->httpClient->get($this->serviceBaseURL, [ 'query' => $requestData ]);
240 240
                     break;
241 241
                 case 'POST':
242
-                    $response = $this->httpClient->post($this->serviceBaseURL, ['form_params' => $requestData]);
242
+                    $response = $this->httpClient->post($this->serviceBaseURL, [ 'form_params' => $requestData ]);
243 243
                     break;
244 244
                 default:
245 245
                     throw new WSException("Unsupported request type {$method}");
246 246
             }
247 247
         } catch (RequestException $ex) {
248
-            $urlFailed = $this->httpClient->getConfig('base_uri') . $this->serviceBaseURL;
248
+            $urlFailed = $this->httpClient->getConfig('base_uri').$this->serviceBaseURL;
249 249
             throw new WSException(
250 250
                 sprintf('Failed to execute %s call on "%s" URL', $method, $urlFailed),
251 251
                 'FAILED_SENDING_REQUEST',
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 
259 259
         return (!is_array($jsonObj) || self::checkForError($jsonObj))
260 260
             ? null
261
-            : $jsonObj['result'];
261
+            : $jsonObj[ 'result' ];
262 262
     }
263 263
 
264 264
     /**
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
         if (!preg_match('/^https?:\/\//i', $baseUrl)) {
274 274
             $baseUrl = sprintf('http://%s', $baseUrl);
275 275
         }
276
-        if (strripos($baseUrl, '/') !== strlen($baseUrl)-1) {
276
+        if (strripos($baseUrl, '/') !== strlen($baseUrl) - 1) {
277 277
             $baseUrl .= '/';
278 278
         }
279 279
         return $baseUrl;
@@ -288,15 +288,15 @@  discard block
 block discarded – undo
288 288
      */
289 289
     private static function checkForError(array $jsonResult)
290 290
     {
291
-        if (isset($jsonResult['success']) && (bool)$jsonResult['success'] === true) {
291
+        if (isset($jsonResult[ 'success' ]) && (bool) $jsonResult[ 'success' ] === true) {
292 292
             return false;
293 293
         }
294 294
 
295
-        if (isset($jsonResult['error'])) {
296
-            $error = $jsonResult['error'];
295
+        if (isset($jsonResult[ 'error' ])) {
296
+            $error = $jsonResult[ 'error' ];
297 297
             throw new WSException(
298
-                $error['message'],
299
-                $error['code']
298
+                $error[ 'message' ],
299
+                $error[ 'code' ]
300 300
             );
301 301
         }
302 302
 
Please login to merge, or discard this patch.