@@ -258,7 +258,7 @@ |
||
| 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 | { |
@@ -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 | /** |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | $this->checkLogin(); |
| 388 | 388 | |
| 389 | 389 | // Make sure the query ends with ; |
| 390 | - $query = (strripos($query, ';') != strlen($query)-1) |
|
| 390 | + $query = (strripos($query, ';') != strlen($query) - 1) |
|
| 391 | 391 | ? trim($query .= ';') |
| 392 | 392 | : trim($query); |
| 393 | 393 | |
@@ -430,13 +430,13 @@ discard block |
||
| 430 | 430 | * @return array $select The list of fields to select (defaults to SQL-like '*' - all the fields) |
| 431 | 431 | * @return int The matching record |
| 432 | 432 | */ |
| 433 | - public function entityRetrieve($moduleName, array $params, array $select = []) |
|
| 433 | + public function entityRetrieve($moduleName, array $params, array $select = [ ]) |
|
| 434 | 434 | { |
| 435 | 435 | $records = $this->entitiesRetrieve($moduleName, $params, $select, 1); |
| 436 | - if (false === $records || !isset($records[0])) { |
|
| 436 | + if (false === $records || !isset($records[ 0 ])) { |
|
| 437 | 437 | return false; |
| 438 | 438 | } |
| 439 | - return $records[0]; |
|
| 439 | + return $records[ 0 ]; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -447,15 +447,15 @@ discard block |
||
| 447 | 447 | */ |
| 448 | 448 | public function entityRetrieveID($moduleName, array $params) // TODO check if params is an assoc array |
| 449 | 449 | { |
| 450 | - $record = $this->entityRetrieve($moduleName, $params, ['id']); |
|
| 451 | - if (false === $record || !isset($record['id'])) { |
|
| 450 | + $record = $this->entityRetrieve($moduleName, $params, [ 'id' ]); |
|
| 451 | + if (false === $record || !isset($record[ 'id' ])) { |
|
| 452 | 452 | return false; |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - $entityID = $record['id']; |
|
| 455 | + $entityID = $record[ 'id' ]; |
|
| 456 | 456 | $entityIDParts = explode('x', $entityID, 2); |
| 457 | 457 | return (is_array($entityIDParts) && count($entityIDParts) === 2) |
| 458 | - ? $entityIDParts[1] |
|
| 458 | + ? $entityIDParts[ 1 ] |
|
| 459 | 459 | : -1; |
| 460 | 460 | } |
| 461 | 461 | |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | $this->checkLogin(); |
| 472 | 472 | |
| 473 | 473 | // Assign record to logged in user if not specified |
| 474 | - if (!isset($params['assigned_user_id'])) { |
|
| 475 | - $params['assigned_user_id'] = $this->userID; |
|
| 474 | + if (!isset($params[ 'assigned_user_id' ])) { |
|
| 475 | + $params[ 'assigned_user_id' ] = $this->userID; |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | $postdata = [ |
@@ -497,19 +497,19 @@ discard block |
||
| 497 | 497 | $this->checkLogin(); |
| 498 | 498 | |
| 499 | 499 | // Assign record to logged in user if not specified |
| 500 | - if (!isset($params['assigned_user_id'])) { |
|
| 501 | - $params['assigned_user_id'] = $this->userID; |
|
| 500 | + if (!isset($params[ 'assigned_user_id' ])) { |
|
| 501 | + $params[ 'assigned_user_id' ] = $this->userID; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | // TODO implement the case when no ID is given |
| 505 | 505 | if (array_key_exists('id', $params)) { |
| 506 | - $data = $this->entityRetrieveByID($moduleName, $params['id']); |
|
| 506 | + $data = $this->entityRetrieveByID($moduleName, $params[ 'id' ]); |
|
| 507 | 507 | if ($data !== false && is_array($data)) { |
| 508 | - $entityID = $data['id']; |
|
| 508 | + $entityID = $data[ 'id' ]; |
|
| 509 | 509 | $params = array_merge( |
| 510 | - $data, // needed to provide mandatory field values |
|
| 511 | - $params, // updated data override |
|
| 512 | - ['id'=>$entityID] // fixing id, might be useful when non <moduleid>x<id> one was specified |
|
| 510 | + $data, // needed to provide mandatory field values |
|
| 511 | + $params, // updated data override |
|
| 512 | + [ 'id'=>$entityID ] // fixing id, might be useful when non <moduleid>x<id> one was specified |
|
| 513 | 513 | ); |
| 514 | 514 | } |
| 515 | 515 | } |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | * @return int $limit limit the list of entries to N records (acts like LIMIT in SQL) |
| 556 | 556 | * @return bool|array The array containing the matching entries or false if nothing was found |
| 557 | 557 | */ |
| 558 | - public function entitiesRetrieve($moduleName, array $params, array $select = [], $limit = 0) |
|
| 558 | + public function entitiesRetrieve($moduleName, array $params, array $select = [ ], $limit = 0) |
|
| 559 | 559 | { |
| 560 | 560 | // Perform re-login if required. |
| 561 | 561 | $this->checkLogin(); |
@@ -568,15 +568,15 @@ discard block |
||
| 568 | 568 | |
| 569 | 569 | // Build the query |
| 570 | 570 | $criteria = array(); |
| 571 | - $select=(empty($select)) ? '*' : implode(',', $select); |
|
| 572 | - $query=sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
| 571 | + $select = (empty($select)) ? '*' : implode(',', $select); |
|
| 572 | + $query = sprintf("SELECT %s FROM $moduleName WHERE ", $select); |
|
| 573 | 573 | foreach ($params as $param => $value) { |
| 574 | - $criteria[] = "{$param} LIKE '{$value}'"; |
|
| 574 | + $criteria[ ] = "{$param} LIKE '{$value}'"; |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | - $query.=implode(" AND ", $criteria); |
|
| 577 | + $query .= implode(" AND ", $criteria); |
|
| 578 | 578 | if (intval($limit) > 0) { |
| 579 | - $query.=sprintf(" LIMIT %s", intval($limit)); |
|
| 579 | + $query .= sprintf(" LIMIT %s", intval($limit)); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | $records = $this->query($query); |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | ]; |
| 610 | 610 | |
| 611 | 611 | if (!empty($moduleName)) { |
| 612 | - $requestData['elementType'] = $moduleName; |
|
| 612 | + $requestData[ 'elementType' ] = $moduleName; |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | return $this->sendHttpRequest($requestData, true); |