@@ -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,15 +460,15 @@ 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 | 467 | |
468 | - $entityID = $records[0]['id']; |
|
468 | + $entityID = $records[ 0 ][ 'id' ]; |
|
469 | 469 | $entityIDParts = explode('x', $entityID, 2); |
470 | 470 | return (is_array($entityIDParts) && count($entityIDParts) === 2) |
471 | - ? $entityIDParts[1] |
|
471 | + ? $entityIDParts[ 1 ] |
|
472 | 472 | : -1; |
473 | 473 | } |
474 | 474 | |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | $entityID = $this->entityRetrieveTypeID($moduleName, $params); |
484 | 484 | $entityIDParts = explode('x', $entityID, 2); |
485 | 485 | return (is_array($entityIDParts) && count($entityIDParts) === 2) |
486 | - ? $entityIDParts[1] |
|
486 | + ? $entityIDParts[ 1 ] |
|
487 | 487 | : -1; |
488 | 488 | } |
489 | 489 | |
@@ -503,8 +503,8 @@ discard block |
||
503 | 503 | $this->checkLogin(); |
504 | 504 | |
505 | 505 | // Assign record to logged in user if not specified |
506 | - if (!isset($params['assigned_user_id'])) { |
|
507 | - $params['assigned_user_id'] = $this->userID; |
|
506 | + if (!isset($params[ 'assigned_user_id' ])) { |
|
507 | + $params[ 'assigned_user_id' ] = $this->userID; |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | $postdata = [ |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | } |
531 | 531 | |
532 | 532 | // Fail if no ID was supplied |
533 | - if (!array_key_exists('id', $params) || empty($params['id'])) { |
|
533 | + if (!array_key_exists('id', $params) || empty($params[ 'id' ])) { |
|
534 | 534 | $this->lastErrorMessage = new WSClientError( |
535 | 535 | "The list of contraints must contain a valid ID" |
536 | 536 | ); |
@@ -541,10 +541,10 @@ discard block |
||
541 | 541 | $this->checkLogin(); |
542 | 542 | |
543 | 543 | // Preprend so-called moduleid if needed |
544 | - $params['id'] = $this->getTypedID($moduleName, $params['id']); |
|
544 | + $params[ 'id' ] = $this->getTypedID($moduleName, $params[ 'id' ]); |
|
545 | 545 | |
546 | 546 | // Check if the entity exists + retrieve its data so it can be used below |
547 | - $entityData = $this->entityRetrieve($moduleName, [ 'id' => $params['id'] ]); |
|
547 | + $entityData = $this->entityRetrieve($moduleName, [ 'id' => $params[ 'id' ] ]); |
|
548 | 548 | if ($entityData === false && !is_array($entityData)) { |
549 | 549 | $this->lastErrorMessage = new WSClientError("Such entity doesn't exist, so it cannot be updated"); |
550 | 550 | return false; |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
599 | 599 | * @return bool|array The array containing matching entries or false if nothing was found |
600 | 600 | */ |
601 | - public function entitiesRetrieve($moduleName, array $params, array $select = [], $limit = 0) |
|
601 | + public function entitiesRetrieve($moduleName, array $params, array $select = [ ], $limit = 0) |
|
602 | 602 | { |
603 | 603 | if (!$this->checkParams($params, 'be able to retrieve entity(ies)')) { |
604 | 604 | return false; |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | ]; |
642 | 642 | |
643 | 643 | if (!empty($moduleName)) { |
644 | - $requestData['elementType'] = $moduleName; |
|
644 | + $requestData[ 'elementType' ] = $moduleName; |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | return $this->sendHttpRequest($requestData, true); |
@@ -655,18 +655,18 @@ discard block |
||
655 | 655 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
656 | 656 | * @return string The query build out of the supplied parameters |
657 | 657 | */ |
658 | - private function buildQuery($moduleName, array $params, array $select = [], $limit = 0) |
|
658 | + private function buildQuery($moduleName, array $params, array $select = [ ], $limit = 0) |
|
659 | 659 | { |
660 | 660 | $criteria = array(); |
661 | - $select=(empty($select)) ? '*' : implode(',', $select); |
|
662 | - $query=sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
661 | + $select = (empty($select)) ? '*' : implode(',', $select); |
|
662 | + $query = sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
663 | 663 | foreach ($params as $param => $value) { |
664 | - $criteria[] = "{$param} LIKE '{$value}'"; |
|
664 | + $criteria[ ] = "{$param} LIKE '{$value}'"; |
|
665 | 665 | } |
666 | 666 | |
667 | - $query.=implode(" AND ", $criteria); |
|
667 | + $query .= implode(" AND ", $criteria); |
|
668 | 668 | if (intval($limit) > 0) { |
669 | - $query.=sprintf(" LIMIT %s", intval($limit)); |
|
669 | + $query .= sprintf(" LIMIT %s", intval($limit)); |
|
670 | 670 | } |
671 | 671 | return $query; |
672 | 672 | } |