@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | /** |
| 259 | 259 | * Gets last operation error, if any |
| 260 | 260 | * @access public |
| 261 | - * @return WSClientError The error object |
|
| 261 | + * @return boolean The error object |
|
| 262 | 262 | */ |
| 263 | 263 | public function getLastError() |
| 264 | 264 | { |
@@ -616,8 +616,8 @@ discard block |
||
| 616 | 616 | * Builds the query using the supplied parameters |
| 617 | 617 | * @param string $moduleName The name of the module / entity type |
| 618 | 618 | * @param array $params Data used to find the matching entries |
| 619 | - * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
|
| 620 | - * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
|
| 619 | + * @return string $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
|
| 620 | + * @return string $limit limit the list of entries to N records (acts like LIMIT in SQL) |
|
| 621 | 621 | * @return string The query build out of the supplied parameters |
| 622 | 622 | */ |
| 623 | 623 | private function buildQuery($moduleName, array $params, array $select = [], $limit = 0) |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | if (!preg_match('/^https?:\/\//i', $url)) { |
| 78 | 78 | $url = sprintf('http://%s', $url); |
| 79 | 79 | } |
| 80 | - if (strripos($url, '/') != (strlen($url)-1)) { |
|
| 80 | + if (strripos($url, '/') != (strlen($url) - 1)) { |
|
| 81 | 81 | $url .= '/'; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | private function checkForError(array $jsonResult) // TODO move checkForError body to sendHttpRequest method's body |
| 97 | 97 | { |
| 98 | - if (isset($jsonResult['success']) && (bool)$jsonResult['success'] === true) { |
|
| 98 | + if (isset($jsonResult[ 'success' ]) && (bool) $jsonResult[ 'success' ] === true) { |
|
| 99 | 99 | $this->lastErrorMessage = null; |
| 100 | 100 | return false; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | $this->lastErrorMessage = new WSClientError( |
| 104 | - $jsonResult['error']['message'], |
|
| 105 | - $jsonResult['error']['code'] |
|
| 104 | + $jsonResult[ 'error' ][ 'message' ], |
|
| 105 | + $jsonResult[ 'error' ][ 'code' ] |
|
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | 108 | return true; |
@@ -132,10 +132,10 @@ discard block |
||
| 132 | 132 | try { |
| 133 | 133 | switch ($method) { |
| 134 | 134 | case 'GET': |
| 135 | - $response = $this->httpClient->get($this->serviceBaseURL, ['query' => $requestData]); |
|
| 135 | + $response = $this->httpClient->get($this->serviceBaseURL, [ 'query' => $requestData ]); |
|
| 136 | 136 | break; |
| 137 | 137 | case 'POST': |
| 138 | - $response = $this->httpClient->post($this->serviceBaseURL, ['form_params' => $requestData]); |
|
| 138 | + $response = $this->httpClient->post($this->serviceBaseURL, [ 'form_params' => $requestData ]); |
|
| 139 | 139 | break; |
| 140 | 140 | default: |
| 141 | 141 | $this->lastErrorMessage = new WSClientError("Unknown request type {$method}"); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | return (!is_array($jsonObj) || $this->checkForError($jsonObj)) |
| 156 | 156 | ? null |
| 157 | - : $jsonObj['result']; |
|
| 157 | + : $jsonObj[ 'result' ]; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | ]; |
| 172 | 172 | $result = $this->sendHttpRequest($getdata, 'GET'); |
| 173 | 173 | |
| 174 | - if (!is_array($result) || !isset($result['token'])) { |
|
| 174 | + if (!is_array($result) || !isset($result[ 'token' ])) { |
|
| 175 | 175 | return false; |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - $this->serviceServerTime = $result['serverTime']; |
|
| 179 | - $this->serviceExpireTime = $result['expireTime']; |
|
| 180 | - $this->serviceToken = $result['token']; |
|
| 178 | + $this->serviceServerTime = $result[ 'serverTime' ]; |
|
| 179 | + $this->serviceExpireTime = $result[ 'expireTime' ]; |
|
| 180 | + $this->serviceToken = $result[ 'token' ]; |
|
| 181 | 181 | |
| 182 | 182 | return true; |
| 183 | 183 | } |
@@ -212,12 +212,12 @@ discard block |
||
| 212 | 212 | $this->accessKey = $accessKey; |
| 213 | 213 | |
| 214 | 214 | // Session data |
| 215 | - $this->sessionName = $result['sessionName']; |
|
| 216 | - $this->userID = $result['userId']; |
|
| 215 | + $this->sessionName = $result[ 'sessionName' ]; |
|
| 216 | + $this->userID = $result[ 'userId' ]; |
|
| 217 | 217 | |
| 218 | 218 | // Vtiger CRM and WebServices API version |
| 219 | - $this->apiVersion = $result['version']; |
|
| 220 | - $this->vtigerVersion = $result['vtigerVersion']; |
|
| 219 | + $this->apiVersion = $result[ 'version' ]; |
|
| 220 | + $this->vtigerVersion = $result[ 'vtigerVersion' ]; |
|
| 221 | 221 | |
| 222 | 222 | return true; |
| 223 | 223 | } |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $accessKey = array_key_exists('accesskey', $result) |
| 252 | - ? $result['accesskey'] |
|
| 253 | - : $result[0]; |
|
| 252 | + ? $result[ 'accesskey' ] |
|
| 253 | + : $result[ 0 ]; |
|
| 254 | 254 | |
| 255 | 255 | return $this->login($username, $accessKey); |
| 256 | 256 | } |
@@ -292,11 +292,11 @@ discard block |
||
| 292 | 292 | ]; |
| 293 | 293 | |
| 294 | 294 | $result = $this->sendHttpRequest($getdata, 'GET'); |
| 295 | - $modules = $result['types']; |
|
| 295 | + $modules = $result[ 'types' ]; |
|
| 296 | 296 | |
| 297 | 297 | $result = array(); |
| 298 | 298 | foreach ($modules as $moduleName) { |
| 299 | - $result[$moduleName] = ['name' => $moduleName]; |
|
| 299 | + $result[ $moduleName ] = [ 'name' => $moduleName ]; |
|
| 300 | 300 | } |
| 301 | 301 | return $result; |
| 302 | 302 | } |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | private function getTypedID($moduleName, $entityID) |
| 332 | 332 | { |
| 333 | - if (stripos((string)$entityID, 'x') !== false) { |
|
| 333 | + if (stripos((string) $entityID, 'x') !== false) { |
|
| 334 | 334 | return $entityID; |
| 335 | 335 | } |
| 336 | 336 | |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | return false; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - return "{$type['idPrefix']}x{$entityID}"; |
|
| 344 | + return "{$type[ 'idPrefix' ]}x{$entityID}"; |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | /** |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | $this->checkLogin(); |
| 394 | 394 | |
| 395 | 395 | // Make sure the query ends with ; |
| 396 | - $query = (strripos($query, ';') != strlen($query)-1) |
|
| 396 | + $query = (strripos($query, ';') != strlen($query) - 1) |
|
| 397 | 397 | ? trim($query .= ';') |
| 398 | 398 | : trim($query); |
| 399 | 399 | |
@@ -436,13 +436,13 @@ discard block |
||
| 436 | 436 | * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
| 437 | 437 | * @return int The matching record |
| 438 | 438 | */ |
| 439 | - public function entityRetrieve($moduleName, array $params, array $select = []) |
|
| 439 | + public function entityRetrieve($moduleName, array $params, array $select = [ ]) |
|
| 440 | 440 | { |
| 441 | 441 | $records = $this->entitiesRetrieve($moduleName, $params, $select, 1); |
| 442 | - if (false === $records || !isset($records[0])) { |
|
| 442 | + if (false === $records || !isset($records[ 0 ])) { |
|
| 443 | 443 | return false; |
| 444 | 444 | } |
| 445 | - return $records[0]; |
|
| 445 | + return $records[ 0 ]; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | /** |
@@ -453,15 +453,15 @@ discard block |
||
| 453 | 453 | */ |
| 454 | 454 | public function entityRetrieveID($moduleName, array $params) // TODO check if params is an assoc array |
| 455 | 455 | { |
| 456 | - $record = $this->entityRetrieve($moduleName, $params, ['id']); |
|
| 457 | - if (false === $record || !isset($record['id'])) { |
|
| 456 | + $record = $this->entityRetrieve($moduleName, $params, [ 'id' ]); |
|
| 457 | + if (false === $record || !isset($record[ 'id' ])) { |
|
| 458 | 458 | return false; |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | - $entityID = $record['id']; |
|
| 461 | + $entityID = $record[ 'id' ]; |
|
| 462 | 462 | $entityIDParts = explode('x', $entityID, 2); |
| 463 | 463 | return (is_array($entityIDParts) && count($entityIDParts) === 2) |
| 464 | - ? $entityIDParts[1] |
|
| 464 | + ? $entityIDParts[ 1 ] |
|
| 465 | 465 | : -1; |
| 466 | 466 | } |
| 467 | 467 | |
@@ -477,8 +477,8 @@ discard block |
||
| 477 | 477 | $this->checkLogin(); |
| 478 | 478 | |
| 479 | 479 | // Assign record to logged in user if not specified |
| 480 | - if (!isset($params['assigned_user_id'])) { |
|
| 481 | - $params['assigned_user_id'] = $this->userID; |
|
| 480 | + if (!isset($params[ 'assigned_user_id' ])) { |
|
| 481 | + $params[ 'assigned_user_id' ] = $this->userID; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | $postdata = [ |
@@ -503,19 +503,19 @@ 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 | // TODO implement the case when no ID is given |
| 511 | 511 | if (array_key_exists('id', $params)) { |
| 512 | - $data = $this->entityRetrieveByID($moduleName, $params['id']); |
|
| 512 | + $data = $this->entityRetrieveByID($moduleName, $params[ 'id' ]); |
|
| 513 | 513 | if ($data !== false && is_array($data)) { |
| 514 | - $entityID = $data['id']; |
|
| 514 | + $entityID = $data[ 'id' ]; |
|
| 515 | 515 | $params = array_merge( |
| 516 | - $data, // needed to provide mandatory field values |
|
| 517 | - $params, // updated data override |
|
| 518 | - ['id'=>$entityID] // fixing id, might be useful when non <moduleid>x<id> one was specified |
|
| 516 | + $data, // needed to provide mandatory field values |
|
| 517 | + $params, // updated data override |
|
| 518 | + [ 'id'=>$entityID ] // fixing id, might be useful when non <moduleid>x<id> one was specified |
|
| 519 | 519 | ); |
| 520 | 520 | } |
| 521 | 521 | } |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
| 562 | 562 | * @return bool|array The array containing the matching entries or false if nothing was found |
| 563 | 563 | */ |
| 564 | - public function entitiesRetrieve($moduleName, array $params, array $select = [], $limit = 0) |
|
| 564 | + public function entitiesRetrieve($moduleName, array $params, array $select = [ ], $limit = 0) |
|
| 565 | 565 | { |
| 566 | 566 | if (empty($params) || !is_array($params) || !$this->isAssocArray($params)) { |
| 567 | 567 | $errorMessage = "You have to specify at least one search parameter (prop => value) in order to filter entities"; |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | ]; |
| 607 | 607 | |
| 608 | 608 | if (!empty($moduleName)) { |
| 609 | - $requestData['elementType'] = $moduleName; |
|
| 609 | + $requestData[ 'elementType' ] = $moduleName; |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | return $this->sendHttpRequest($requestData, true); |
@@ -620,18 +620,18 @@ discard block |
||
| 620 | 620 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
| 621 | 621 | * @return string The query build out of the supplied parameters |
| 622 | 622 | */ |
| 623 | - private function buildQuery($moduleName, array $params, array $select = [], $limit = 0) |
|
| 623 | + private function buildQuery($moduleName, array $params, array $select = [ ], $limit = 0) |
|
| 624 | 624 | { |
| 625 | 625 | $criteria = array(); |
| 626 | - $select=(empty($select)) ? '*' : implode(',', $select); |
|
| 627 | - $query=sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
| 626 | + $select = (empty($select)) ? '*' : implode(',', $select); |
|
| 627 | + $query = sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
| 628 | 628 | foreach ($params as $param => $value) { |
| 629 | - $criteria[] = "{$param} LIKE '{$value}'"; |
|
| 629 | + $criteria[ ] = "{$param} LIKE '{$value}'"; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - $query.=implode(" AND ", $criteria); |
|
| 632 | + $query .= implode(" AND ", $criteria); |
|
| 633 | 633 | if (intval($limit) > 0) { |
| 634 | - $query.=sprintf(" LIMIT %s", intval($limit)); |
|
| 634 | + $query .= sprintf(" LIMIT %s", intval($limit)); |
|
| 635 | 635 | } |
| 636 | 636 | return $query; |
| 637 | 637 | } |