@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | if (!preg_match('/^https?:\/\//i', $url)) { |
79 | 79 | $url = sprintf('http://%s', $url); |
80 | 80 | } |
81 | - if (strripos($url, '/') != (strlen($url)-1)) { |
|
81 | + if (strripos($url, '/') != (strlen($url) - 1)) { |
|
82 | 82 | $url .= '/'; |
83 | 83 | } |
84 | 84 | |
@@ -96,14 +96,14 @@ discard block |
||
96 | 96 | */ |
97 | 97 | private function checkForError(array $jsonResult) |
98 | 98 | { |
99 | - if (isset($jsonResult['success']) && (bool)$jsonResult['success'] === true) { |
|
99 | + if (isset($jsonResult[ 'success' ]) && (bool) $jsonResult[ 'success' ] === true) { |
|
100 | 100 | $this->lastErrorMessage = null; |
101 | 101 | return false; |
102 | 102 | } |
103 | 103 | |
104 | 104 | $this->lastErrorMessage = new WSClientError( |
105 | - $jsonResult['error']['message'], |
|
106 | - $jsonResult['error']['code'] |
|
105 | + $jsonResult[ 'error' ][ 'message' ], |
|
106 | + $jsonResult[ 'error' ][ 'code' ] |
|
107 | 107 | ); |
108 | 108 | |
109 | 109 | return true; |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | try { |
134 | 134 | switch ($method) { |
135 | 135 | case 'GET': |
136 | - $response = $this->httpClient->get($this->serviceBaseURL, ['query' => $requestData]); |
|
136 | + $response = $this->httpClient->get($this->serviceBaseURL, [ 'query' => $requestData ]); |
|
137 | 137 | break; |
138 | 138 | case 'POST': |
139 | - $response = $this->httpClient->post($this->serviceBaseURL, ['form_params' => $requestData]); |
|
139 | + $response = $this->httpClient->post($this->serviceBaseURL, [ 'form_params' => $requestData ]); |
|
140 | 140 | break; |
141 | 141 | default: |
142 | 142 | $this->lastErrorMessage = new WSClientError("Unknown request type {$method}"); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | |
156 | 156 | return (!is_array($jsonObj) || $this->checkForError($jsonObj)) |
157 | 157 | ? null |
158 | - : $jsonObj['result']; |
|
158 | + : $jsonObj[ 'result' ]; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -172,13 +172,13 @@ discard block |
||
172 | 172 | ]; |
173 | 173 | $result = $this->sendHttpRequest($getdata, 'GET'); |
174 | 174 | |
175 | - if (!is_array($result) || !isset($result['token'])) { |
|
175 | + if (!is_array($result) || !isset($result[ 'token' ])) { |
|
176 | 176 | return false; |
177 | 177 | } |
178 | 178 | |
179 | - $this->serviceServerTime = $result['serverTime']; |
|
180 | - $this->serviceExpireTime = $result['expireTime']; |
|
181 | - $this->serviceToken = $result['token']; |
|
179 | + $this->serviceServerTime = $result[ 'serverTime' ]; |
|
180 | + $this->serviceExpireTime = $result[ 'expireTime' ]; |
|
181 | + $this->serviceToken = $result[ 'token' ]; |
|
182 | 182 | |
183 | 183 | return true; |
184 | 184 | } |
@@ -213,12 +213,12 @@ discard block |
||
213 | 213 | $this->accessKey = $accessKey; |
214 | 214 | |
215 | 215 | // Session data |
216 | - $this->sessionName = $result['sessionName']; |
|
217 | - $this->userID = $result['userId']; |
|
216 | + $this->sessionName = $result[ 'sessionName' ]; |
|
217 | + $this->userID = $result[ 'userId' ]; |
|
218 | 218 | |
219 | 219 | // Vtiger CRM and WebServices API version |
220 | - $this->apiVersion = $result['version']; |
|
221 | - $this->vtigerVersion = $result['vtigerVersion']; |
|
220 | + $this->apiVersion = $result[ 'version' ]; |
|
221 | + $this->vtigerVersion = $result[ 'vtigerVersion' ]; |
|
222 | 222 | |
223 | 223 | return true; |
224 | 224 | } |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | } |
251 | 251 | |
252 | 252 | $accessKey = array_key_exists('accesskey', $result) |
253 | - ? $result['accesskey'] |
|
254 | - : $result[0]; |
|
253 | + ? $result[ 'accesskey' ] |
|
254 | + : $result[ 0 ]; |
|
255 | 255 | |
256 | 256 | return $this->login($username, $accessKey); |
257 | 257 | } |
@@ -293,11 +293,11 @@ discard block |
||
293 | 293 | ]; |
294 | 294 | |
295 | 295 | $result = $this->sendHttpRequest($getdata, 'GET'); |
296 | - $modules = $result['types']; |
|
296 | + $modules = $result[ 'types' ]; |
|
297 | 297 | |
298 | 298 | $result = array(); |
299 | 299 | foreach ($modules as $moduleName) { |
300 | - $result[$moduleName] = ['name' => $moduleName]; |
|
300 | + $result[ $moduleName ] = [ 'name' => $moduleName ]; |
|
301 | 301 | } |
302 | 302 | return $result; |
303 | 303 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | */ |
332 | 332 | private function getTypedID($moduleName, $entityID) |
333 | 333 | { |
334 | - if (stripos((string)$entityID, 'x') !== false) { |
|
334 | + if (stripos((string) $entityID, 'x') !== false) { |
|
335 | 335 | return $entityID; |
336 | 336 | } |
337 | 337 | |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | return false; |
347 | 347 | } |
348 | 348 | |
349 | - return "{$type['idPrefix']}x{$entityID}"; |
|
349 | + return "{$type[ 'idPrefix' ]}x{$entityID}"; |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | $this->checkLogin(); |
401 | 401 | |
402 | 402 | // Make sure the query ends with ; |
403 | - $query = (strripos($query, ';') != strlen($query)-1) |
|
403 | + $query = (strripos($query, ';') != strlen($query) - 1) |
|
404 | 404 | ? trim($query .= ';') |
405 | 405 | : trim($query); |
406 | 406 | |
@@ -443,13 +443,13 @@ discard block |
||
443 | 443 | * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
444 | 444 | * @return int The matching record |
445 | 445 | */ |
446 | - public function entityRetrieve($moduleName, array $params, array $select = []) |
|
446 | + public function entityRetrieve($moduleName, array $params, array $select = [ ]) |
|
447 | 447 | { |
448 | 448 | $records = $this->entitiesRetrieve($moduleName, $params, $select, 1); |
449 | - if (false === $records || !isset($records[0])) { |
|
449 | + if (false === $records || !isset($records[ 0 ])) { |
|
450 | 450 | return false; |
451 | 451 | } |
452 | - return $records[0]; |
|
452 | + return $records[ 0 ]; |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -460,11 +460,11 @@ discard block |
||
460 | 460 | */ |
461 | 461 | public function entityRetrieveTypeID($moduleName, array $params) |
462 | 462 | { |
463 | - $records = $this->entitiesRetrieve($moduleName, $params, ['id'], 1); |
|
464 | - if (false === $records || !isset($records[0]['id']) || empty($records[0]['id'])) { |
|
463 | + $records = $this->entitiesRetrieve($moduleName, $params, [ 'id' ], 1); |
|
464 | + if (false === $records || !isset($records[ 0 ][ 'id' ]) || empty($records[ 0 ][ 'id' ])) { |
|
465 | 465 | return false; |
466 | 466 | } |
467 | - return $records[0]['id']; |
|
467 | + return $records[ 0 ][ 'id' ]; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | $entityID = $this->entityRetrieveTypeID($moduleName, $params); |
479 | 479 | $entityIDParts = explode('x', $entityID, 2); |
480 | 480 | return (is_array($entityIDParts) && count($entityIDParts) === 2) |
481 | - ? $entityIDParts[1] |
|
481 | + ? $entityIDParts[ 1 ] |
|
482 | 482 | : -1; |
483 | 483 | } |
484 | 484 | |
@@ -498,8 +498,8 @@ discard block |
||
498 | 498 | $this->checkLogin(); |
499 | 499 | |
500 | 500 | // Assign record to logged in user if not specified |
501 | - if (!isset($params['assigned_user_id'])) { |
|
502 | - $params['assigned_user_id'] = $this->userID; |
|
501 | + if (!isset($params[ 'assigned_user_id' ])) { |
|
502 | + $params[ 'assigned_user_id' ] = $this->userID; |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | $postdata = [ |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | } |
526 | 526 | |
527 | 527 | // Fail if no ID was supplied |
528 | - if (!array_key_exists('id', $params) || empty($params['id'])) { |
|
528 | + if (!array_key_exists('id', $params) || empty($params[ 'id' ])) { |
|
529 | 529 | $this->lastErrorMessage = new WSClientError( |
530 | 530 | "The list of contraints must contain a valid ID" |
531 | 531 | ); |
@@ -536,10 +536,10 @@ discard block |
||
536 | 536 | $this->checkLogin(); |
537 | 537 | |
538 | 538 | // Preprend so-called moduleid if needed |
539 | - $params['id'] = $this->getTypedID($moduleName, $params['id']); |
|
539 | + $params[ 'id' ] = $this->getTypedID($moduleName, $params[ 'id' ]); |
|
540 | 540 | |
541 | 541 | // Check if the entity exists + retrieve its data so it can be used below |
542 | - $entityData = $this->entityRetrieve($moduleName, [ 'id' => $params['id'] ]); |
|
542 | + $entityData = $this->entityRetrieve($moduleName, [ 'id' => $params[ 'id' ] ]); |
|
543 | 543 | if ($entityData === false && !is_array($entityData)) { |
544 | 544 | $this->lastErrorMessage = new WSClientError("Such entity doesn't exist, so it cannot be updated"); |
545 | 545 | return false; |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
594 | 594 | * @return bool|array The array containing matching entries or false if nothing was found |
595 | 595 | */ |
596 | - public function entitiesRetrieve($moduleName, array $params, array $select = [], $limit = 0) |
|
596 | + public function entitiesRetrieve($moduleName, array $params, array $select = [ ], $limit = 0) |
|
597 | 597 | { |
598 | 598 | if (!$this->checkParams($params, 'be able to retrieve entity(ies)')) { |
599 | 599 | return false; |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | ]; |
637 | 637 | |
638 | 638 | if (!empty($moduleName)) { |
639 | - $requestData['elementType'] = $moduleName; |
|
639 | + $requestData[ 'elementType' ] = $moduleName; |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | return $this->sendHttpRequest($requestData, true); |
@@ -650,18 +650,18 @@ discard block |
||
650 | 650 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
651 | 651 | * @return string The query build out of the supplied parameters |
652 | 652 | */ |
653 | - private function buildQuery($moduleName, array $params, array $select = [], $limit = 0) |
|
653 | + private function buildQuery($moduleName, array $params, array $select = [ ], $limit = 0) |
|
654 | 654 | { |
655 | 655 | $criteria = array(); |
656 | - $select=(empty($select)) ? '*' : implode(',', $select); |
|
657 | - $query=sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
656 | + $select = (empty($select)) ? '*' : implode(',', $select); |
|
657 | + $query = sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
658 | 658 | foreach ($params as $param => $value) { |
659 | - $criteria[] = "{$param} LIKE '{$value}'"; |
|
659 | + $criteria[ ] = "{$param} LIKE '{$value}'"; |
|
660 | 660 | } |
661 | 661 | |
662 | - $query.=implode(" AND ", $criteria); |
|
662 | + $query .= implode(" AND ", $criteria); |
|
663 | 663 | if (intval($limit) > 0) { |
664 | - $query.=sprintf(" LIMIT %s", intval($limit)); |
|
664 | + $query .= sprintf(" LIMIT %s", intval($limit)); |
|
665 | 665 | } |
666 | 666 | return $query; |
667 | 667 | } |