@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * Gets a challenge token from the server and stores for future requests |
163 | 163 | * @access private |
164 | 164 | * @param string $username VTiger user name |
165 | - * @return booleanReturns false in case of failure |
|
165 | + * @return boolean false in case of failure |
|
166 | 166 | */ |
167 | 167 | private function passChallenge($username) |
168 | 168 | { |
@@ -625,8 +625,8 @@ discard block |
||
625 | 625 | * Builds the query using the supplied parameters |
626 | 626 | * @param string $moduleName The name of the module / entity type |
627 | 627 | * @param array $params Data used to find matching entries |
628 | - * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
|
629 | - * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
|
628 | + * @return string $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
|
629 | + * @return string $limit limit the list of entries to N records (acts like LIMIT in SQL) |
|
630 | 630 | * @return string The query build out of the supplied parameters |
631 | 631 | */ |
632 | 632 | private function buildQuery($moduleName, array $params, array $select = [], $limit = 0) |
@@ -648,6 +648,7 @@ discard block |
||
648 | 648 | /** |
649 | 649 | * Checks if if params holds valid entity data/search constraints, otherwise returns false |
650 | 650 | * @param array $params Array holding entity data/search constraints |
651 | + * @param string $paramsPurpose |
|
651 | 652 | * @return boolean Returns true if params holds valid entity data/search constraints, otherwise returns false |
652 | 653 | */ |
653 | 654 | private function checkParams(array $params, $paramsPurpose) |
@@ -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 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | return false; |
343 | 343 | } |
344 | 344 | |
345 | - return "{$type['idPrefix']}x{$entityID}"; |
|
345 | + return "{$type[ 'idPrefix' ]}x{$entityID}"; |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | $this->checkLogin(); |
397 | 397 | |
398 | 398 | // Make sure the query ends with ; |
399 | - $query = (strripos($query, ';') != strlen($query)-1) |
|
399 | + $query = (strripos($query, ';') != strlen($query) - 1) |
|
400 | 400 | ? trim($query .= ';') |
401 | 401 | : trim($query); |
402 | 402 | |
@@ -439,13 +439,13 @@ discard block |
||
439 | 439 | * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
440 | 440 | * @return int The matching record |
441 | 441 | */ |
442 | - public function entityRetrieve($moduleName, array $params, array $select = []) |
|
442 | + public function entityRetrieve($moduleName, array $params, array $select = [ ]) |
|
443 | 443 | { |
444 | 444 | $records = $this->entitiesRetrieve($moduleName, $params, $select, 1); |
445 | - if (false === $records || !isset($records[0])) { |
|
445 | + if (false === $records || !isset($records[ 0 ])) { |
|
446 | 446 | return false; |
447 | 447 | } |
448 | - return $records[0]; |
|
448 | + return $records[ 0 ]; |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -456,15 +456,15 @@ discard block |
||
456 | 456 | */ |
457 | 457 | public function entityRetrieveID($moduleName, array $params) |
458 | 458 | { |
459 | - $record = $this->entityRetrieve($moduleName, $params, ['id']); |
|
460 | - if (false === $record || !isset($record['id'])) { |
|
459 | + $record = $this->entityRetrieve($moduleName, $params, [ 'id' ]); |
|
460 | + if (false === $record || !isset($record[ 'id' ])) { |
|
461 | 461 | return false; |
462 | 462 | } |
463 | 463 | |
464 | - $entityID = $record['id']; |
|
464 | + $entityID = $record[ 'id' ]; |
|
465 | 465 | $entityIDParts = explode('x', $entityID, 2); |
466 | 466 | return (is_array($entityIDParts) && count($entityIDParts) === 2) |
467 | - ? $entityIDParts[1] |
|
467 | + ? $entityIDParts[ 1 ] |
|
468 | 468 | : -1; |
469 | 469 | } |
470 | 470 | |
@@ -484,8 +484,8 @@ discard block |
||
484 | 484 | $this->checkLogin(); |
485 | 485 | |
486 | 486 | // Assign record to logged in user if not specified |
487 | - if (!isset($params['assigned_user_id'])) { |
|
488 | - $params['assigned_user_id'] = $this->userID; |
|
487 | + if (!isset($params[ 'assigned_user_id' ])) { |
|
488 | + $params[ 'assigned_user_id' ] = $this->userID; |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | $postdata = [ |
@@ -514,19 +514,19 @@ discard block |
||
514 | 514 | $this->checkLogin(); |
515 | 515 | |
516 | 516 | // Assign record to logged in user if not specified |
517 | - if (!isset($params['assigned_user_id'])) { |
|
518 | - $params['assigned_user_id'] = $this->userID; |
|
517 | + if (!isset($params[ 'assigned_user_id' ])) { |
|
518 | + $params[ 'assigned_user_id' ] = $this->userID; |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | // TODO implement the case when no ID is given |
522 | 522 | if (array_key_exists('id', $params)) { |
523 | - $data = $this->entityRetrieveByID($moduleName, $params['id']); |
|
523 | + $data = $this->entityRetrieveByID($moduleName, $params[ 'id' ]); |
|
524 | 524 | if ($data !== false && is_array($data)) { |
525 | - $entityID = $data['id']; |
|
525 | + $entityID = $data[ 'id' ]; |
|
526 | 526 | $params = array_merge( |
527 | - $data, // needed to provide mandatory field values |
|
528 | - $params, // updated data override |
|
529 | - ['id'=>$entityID] // fixing id, might be useful when non <moduleid>x<id> one was specified |
|
527 | + $data, // needed to provide mandatory field values |
|
528 | + $params, // updated data override |
|
529 | + [ 'id'=>$entityID ] // fixing id, might be useful when non <moduleid>x<id> one was specified |
|
530 | 530 | ); |
531 | 531 | } |
532 | 532 | } |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
573 | 573 | * @return bool|array The array containing matching entries or false if nothing was found |
574 | 574 | */ |
575 | - public function entitiesRetrieve($moduleName, array $params, array $select = [], $limit = 0) |
|
575 | + public function entitiesRetrieve($moduleName, array $params, array $select = [ ], $limit = 0) |
|
576 | 576 | { |
577 | 577 | if (!$this->checkParams($params, 'be able to retrieve entity(ies)')) { |
578 | 578 | return false; |
@@ -615,7 +615,7 @@ discard block |
||
615 | 615 | ]; |
616 | 616 | |
617 | 617 | if (!empty($moduleName)) { |
618 | - $requestData['elementType'] = $moduleName; |
|
618 | + $requestData[ 'elementType' ] = $moduleName; |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | return $this->sendHttpRequest($requestData, true); |
@@ -629,18 +629,18 @@ discard block |
||
629 | 629 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
630 | 630 | * @return string The query build out of the supplied parameters |
631 | 631 | */ |
632 | - private function buildQuery($moduleName, array $params, array $select = [], $limit = 0) |
|
632 | + private function buildQuery($moduleName, array $params, array $select = [ ], $limit = 0) |
|
633 | 633 | { |
634 | 634 | $criteria = array(); |
635 | - $select=(empty($select)) ? '*' : implode(',', $select); |
|
636 | - $query=sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
635 | + $select = (empty($select)) ? '*' : implode(',', $select); |
|
636 | + $query = sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
637 | 637 | foreach ($params as $param => $value) { |
638 | - $criteria[] = "{$param} LIKE '{$value}'"; |
|
638 | + $criteria[ ] = "{$param} LIKE '{$value}'"; |
|
639 | 639 | } |
640 | 640 | |
641 | - $query.=implode(" AND ", $criteria); |
|
641 | + $query .= implode(" AND ", $criteria); |
|
642 | 642 | if (intval($limit) > 0) { |
643 | - $query.=sprintf(" LIMIT %s", intval($limit)); |
|
643 | + $query .= sprintf(" LIMIT %s", intval($limit)); |
|
644 | 644 | } |
645 | 645 | return $query; |
646 | 646 | } |