Completed
Push — master ( 4c707a...1e14b3 )
by Zhmayev
01:23
created
src/Entities.php 4 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -244,6 +244,7 @@  discard block
 block discarded – undo
244 244
      * @access public
245 245
      * @static
246 246
      * @param  array    $params  Array holding entity data/search constraints
247
+     * @param string $paramsPurpose
247 248
      * @return boolean  Returns true if params holds valid entity data/search constraints, otherwise returns false
248 249
      */
249 250
     private static function checkParams(array $params, $paramsPurpose)
@@ -263,8 +264,8 @@  discard block
 block discarded – undo
263 264
      * @static
264 265
      * @param  string   $moduleName  The name of the module / entity type
265 266
      * @param  array    $params  Data used to find matching entries
266
-     * @return array    $select  The list of fields to select (defaults to SQL-like '*' - all the fields)
267
-     * @return int      $limit  limit the list of entries to N records (acts like LIMIT in SQL)
267
+     * @return string    $select  The list of fields to select (defaults to SQL-like '*' - all the fields)
268
+     * @return string      $limit  limit the list of entries to N records (acts like LIMIT in SQL)
268 269
      * @return string   The query build out of the supplied parameters
269 270
      */
270 271
     public static function getQueryString($moduleName, array $params, array $select = [], $limit = 0)
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,6 @@
 block discarded – undo
32 32
 namespace Salaros\Vtiger\VTWSCLib;
33 33
 
34 34
 use Salaros\Vtiger\VTWSCLib\WSClient;
35
-use Salaros\Vtiger\VTWSCLib\EntityUtils;
36 35
 
37 36
 /**
38 37
 * Vtiger Web Services PHP Client Session class
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -240,12 +240,12 @@
 block discarded – undo
240 240
     }
241 241
 
242 242
         /**
243
-     * Checks if if params holds valid entity data/search constraints, otherwise returns false
244
-     * @access public
245
-     * @static
246
-     * @param  array    $params  Array holding entity data/search constraints
247
-     * @return boolean  Returns true if params holds valid entity data/search constraints, otherwise returns false
248
-     */
243
+         * Checks if if params holds valid entity data/search constraints, otherwise returns false
244
+         * @access public
245
+         * @static
246
+         * @param  array    $params  Array holding entity data/search constraints
247
+         * @return boolean  Returns true if params holds valid entity data/search constraints, otherwise returns false
248
+         */
249 249
     private static function checkParams(array $params, $paramsPurpose)
250 250
     {
251 251
         if (empty($params) || !is_array($params) || !is_assoc_array($params)) {
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      * @return array   $select  The list of fields to select (defaults to SQL-like '*' - all the fields)
61 61
      * @return boolean  Entity data
62 62
      */
63
-    public function findOneByID($moduleName, $entityID, array $select = [])
63
+    public function findOneByID($moduleName, $entityID, array $select = [ ])
64 64
     {
65 65
         return $this->findOne($moduleName, [ 'id' => $entityID ], $select);
66 66
     }
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
      * @return array   $select  The list of fields to select (defaults to SQL-like '*' - all the fields)
73 73
      * @return integer  The matching record
74 74
      */
75
-    public function findOne($moduleName, array $params, array $select = [])
75
+    public function findOne($moduleName, array $params, array $select = [ ])
76 76
     {
77 77
         $records = $this->findMany($moduleName, $params, $select, 1);
78
-        if (false === $records || !isset($records[0])) {
78
+        if (false === $records || !isset($records[ 0 ])) {
79 79
             return false;
80 80
         }
81
-        return $records[0];
81
+        return $records[ 0 ];
82 82
     }
83 83
 
84 84
     /**
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function getID($moduleName, array $params)
91 91
     {
92
-        $record = $this->findOne($moduleName, $params, ['id']);
93
-        if (false === $record || !isset($record['id']) || empty($record['id'])) {
92
+        $record = $this->findOne($moduleName, $params, [ 'id' ]);
93
+        if (false === $record || !isset($record[ 'id' ]) || empty($record[ 'id' ])) {
94 94
             return false;
95 95
         }
96
-        return $record['id'];
96
+        return $record[ 'id' ];
97 97
     }
98 98
 
99 99
     /**
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
         $entityID = $this->getID($moduleName, $params);
108 108
         $entityIDParts = explode('x', $entityID, 2);
109 109
         return (is_array($entityIDParts) && count($entityIDParts) === 2)
110
-            ? intval($entityIDParts[1])
110
+            ? intval($entityIDParts[ 1 ])
111 111
             : -1;
112 112
     }
113 113
 
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
         }
125 125
 
126 126
         // Assign record to logged in user if not specified
127
-        if (!isset($params['assigned_user_id'])) {
128
-            $params['assigned_user_id'] = $this->userID;
127
+        if (!isset($params[ 'assigned_user_id' ])) {
128
+            $params[ 'assigned_user_id' ] = $this->userID;
129 129
         }
130 130
 
131 131
         $requestData = [
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      * @return integer      $limit  limit the list of entries to N records (acts like LIMIT in SQL)
199 199
      * @return bool|array  The array containing matching entries or false if nothing was found
200 200
      */
201
-    public function findMany($moduleName, array $params, array $select = [], $limit = 0)
201
+    public function findMany($moduleName, array $params, array $select = [ ], $limit = 0)
202 202
     {
203 203
         if (!self::checkParams($params, 'be able to retrieve entity(ies)')) {
204 204
             return false;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
         ];
234 234
 
235 235
         if (!empty($moduleName)) {
236
-            $requestData['elementType'] = $moduleName;
236
+            $requestData[ 'elementType' ] = $moduleName;
237 237
         }
238 238
 
239 239
         return $this->wsClient->invokeOperation('sync', $requestData, true);
@@ -267,18 +267,18 @@  discard block
 block discarded – undo
267 267
      * @return int      $limit  limit the list of entries to N records (acts like LIMIT in SQL)
268 268
      * @return string   The query build out of the supplied parameters
269 269
      */
270
-    public static function getQueryString($moduleName, array $params, array $select = [], $limit = 0)
270
+    public static function getQueryString($moduleName, array $params, array $select = [ ], $limit = 0)
271 271
     {
272 272
         $criteria = array();
273
-        $select=(empty($select)) ? '*' : implode(',', $select);
274
-        $query=sprintf("SELECT %s FROM $moduleName WHERE ", $select);
273
+        $select = (empty($select)) ? '*' : implode(',', $select);
274
+        $query = sprintf("SELECT %s FROM $moduleName WHERE ", $select);
275 275
         foreach ($params as $param => $value) {
276
-            $criteria[] = "{$param} LIKE '{$value}'";
276
+            $criteria[ ] = "{$param} LIKE '{$value}'";
277 277
         }
278 278
 
279
-        $query.=implode(" AND ", $criteria);
279
+        $query .= implode(" AND ", $criteria);
280 280
         if (intval($limit) > 0) {
281
-            $query.=sprintf(" LIMIT %s", intval($limit));
281
+            $query .= sprintf(" LIMIT %s", intval($limit));
282 282
         }
283 283
         return $query;
284 284
     }
Please login to merge, or discard this patch.
src/Session.php 2 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * Gets a challenge token from the server and stores for future requests
173 173
      * @access private
174 174
      * @param  string $username VTiger user name
175
-     * @return booleanReturns false in case of failure
175
+     * @return boolean false in case of failure
176 176
      */
177 177
     private function passChallenge($username)
178 178
     {
@@ -246,6 +246,7 @@  discard block
 block discarded – undo
246 246
      * @access private
247 247
      * @static
248 248
      * @param  string  Base URL of vTiger CRM
249
+     * @param string $baseUrl
249 250
      * @return boolean Returns cleaned and fixed vTiger URL
250 251
      */
251 252
     private static function fixVtigerBaseUrl($baseUrl)
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         $postdata = [
101 101
             'operation' => 'login',
102 102
             'username'  => $username,
103
-            'accessKey' => md5($this->serviceToken . $accessKey)
103
+            'accessKey' => md5($this->serviceToken.$accessKey)
104 104
         ];
105 105
 
106 106
         $result = $this->sendHttpRequest($postdata);
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
         $this->accessKey = $accessKey;
114 114
 
115 115
         // Session data
116
-        $this->sessionName = $result['sessionName'];
117
-        $this->userID = $result['userId'];
116
+        $this->sessionName = $result[ 'sessionName' ];
117
+        $this->userID = $result[ 'userId' ];
118 118
 
119 119
         // Vtiger CRM and WebServices API version
120
-        $this->apiVersion = $result['version'];
121
-        $this->vtigerVersion = $result['vtigerVersion'];
120
+        $this->apiVersion = $result[ 'version' ];
121
+        $this->vtigerVersion = $result[ 'vtigerVersion' ];
122 122
 
123 123
         return true;
124 124
     }
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
         }
151 151
 
152 152
         $this->accessKey = array_key_exists('accesskey', $result)
153
-            ? $result['accesskey']
154
-            : $result[0];
153
+            ? $result[ 'accesskey' ]
154
+            : $result[ 0 ];
155 155
 
156 156
         return $this->login($username, $accessKey);
157 157
     }
@@ -182,13 +182,13 @@  discard block
 block discarded – undo
182 182
         ];
183 183
         $result = $this->sendHttpRequest($getdata, 'GET');
184 184
         
185
-        if (!is_array($result) || !isset($result['token'])) {
185
+        if (!is_array($result) || !isset($result[ 'token' ])) {
186 186
             return false;
187 187
         }
188 188
 
189
-        $this->serviceServerTime = $result['serverTime'];
190
-        $this->serviceExpireTime = $result['expireTime'];
191
-        $this->serviceToken = $result['token'];
189
+        $this->serviceServerTime = $result[ 'serverTime' ];
190
+        $this->serviceExpireTime = $result[ 'expireTime' ];
191
+        $this->serviceToken = $result[ 'token' ];
192 192
 
193 193
         return true;
194 194
     }
@@ -202,30 +202,30 @@  discard block
 block discarded – undo
202 202
      */
203 203
     public function sendHttpRequest(array $requestData, $method = 'POST')
204 204
     {
205
-        if (!isset($requestData['operation'])) {
205
+        if (!isset($requestData[ 'operation' ])) {
206 206
             throw new WSException('Request data must contain the name of the operation!');
207 207
         }
208 208
 
209
-        $requestData['sessionName'] = $this->sessionName;
209
+        $requestData[ 'sessionName' ] = $this->sessionName;
210 210
 
211 211
         // Perform re-login if required.
212
-        if ('getchallenge' !== $requestData['operation'] && time() > $this->serviceExpireTime) {
212
+        if ('getchallenge' !== $requestData[ 'operation' ] && time() > $this->serviceExpireTime) {
213 213
             $this->login($this->userName, $this->accessKey);
214 214
         }
215 215
         
216 216
         try {
217 217
             switch ($method) {
218 218
                 case 'GET':
219
-                    $response = $this->httpClient->get($this->serviceBaseURL, ['query' => $requestData]);
219
+                    $response = $this->httpClient->get($this->serviceBaseURL, [ 'query' => $requestData ]);
220 220
                     break;
221 221
                 case 'POST':
222
-                    $response = $this->httpClient->post($this->serviceBaseURL, ['form_params' => $requestData]);
222
+                    $response = $this->httpClient->post($this->serviceBaseURL, [ 'form_params' => $requestData ]);
223 223
                     break;
224 224
                 default:
225 225
                     throw new WSException("Unsupported request type {$method}");
226 226
             }
227 227
         } catch (RequestException $ex) {
228
-            $urlFailed = $this->httpClient->getConfig('base_uri') . $this->serviceBaseURL;
228
+            $urlFailed = $this->httpClient->getConfig('base_uri').$this->serviceBaseURL;
229 229
             throw new WSException(
230 230
                 sprintf('Failed to execute %s call on "%s" URL', $method, $urlFailed),
231 231
                 'FAILED_SENDING_REQUEST',
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 
239 239
         return (!is_array($jsonObj) || self::checkForError($jsonObj))
240 240
             ? null
241
-            : $jsonObj['result'];
241
+            : $jsonObj[ 'result' ];
242 242
     }
243 243
 
244 244
     /**
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         if (!preg_match('/^https?:\/\//i', $baseUrl)) {
254 254
             $baseUrl = sprintf('http://%s', $baseUrl);
255 255
         }
256
-        if (strripos($baseUrl, '/') !== strlen($baseUrl)-1) {
256
+        if (strripos($baseUrl, '/') !== strlen($baseUrl) - 1) {
257 257
             $baseUrl .= '/';
258 258
         }
259 259
         return $baseUrl;
@@ -268,15 +268,15 @@  discard block
 block discarded – undo
268 268
      */
269 269
     private static function checkForError(array $jsonResult)
270 270
     {
271
-        if (isset($jsonResult['success']) && (bool)$jsonResult['success'] === true) {
271
+        if (isset($jsonResult[ 'success' ]) && (bool) $jsonResult[ 'success' ] === true) {
272 272
             return false;
273 273
         }
274 274
 
275
-        if (isset($jsonResult['error'])) {
276
-            $error = $jsonResult['error'];
275
+        if (isset($jsonResult[ 'error' ])) {
276
+            $error = $jsonResult[ 'error' ];
277 277
             throw new WSException(
278
-                $error['message'],
279
-                $error['code']
278
+                $error[ 'message' ],
279
+                $error[ 'code' ]
280 280
             );
281 281
         }
282 282
 
Please login to merge, or discard this patch.
src/WSClient.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
             );
108 108
         }
109 109
 
110
-        $params['operation'] = $operation;
110
+        $params[ 'operation' ] = $operation;
111 111
         return $this->session->sendHttpRequest($params, $method);
112 112
     }
113 113
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     public function runQuery($query)
127 127
     {
128 128
         // Make sure the query ends with ;
129
-        $query = (strripos($query, ';') != strlen($query)-1)
129
+        $query = (strripos($query, ';') != strlen($query) - 1)
130 130
             ? trim($query .= ';')
131 131
             : trim($query);
132 132
 
Please login to merge, or discard this patch.
src/Modules.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function getAll()
61 61
     {
62
-        $result = $this->wsClient->invokeOperation('listtypes', [], 'GET');
63
-        $modules = $result['types'];
62
+        $result = $this->wsClient->invokeOperation('listtypes', [ ], 'GET');
63
+        $modules = $result[ 'types' ];
64 64
 
65 65
         $result = array();
66 66
         foreach ($modules as $moduleName) {
67
-            $result[$moduleName] = ['name' => $moduleName];
67
+            $result[ $moduleName ] = [ 'name' => $moduleName ];
68 68
         }
69 69
         return $result;
70 70
     }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function getTypedID($moduleName, $entityID)
91 91
     {
92
-        if (stripos((string)$entityID, 'x') !== false) {
92
+        if (stripos((string) $entityID, 'x') !== false) {
93 93
             return $entityID;
94 94
         }
95 95
 
@@ -103,6 +103,6 @@  discard block
 block discarded – undo
103 103
             throw new WSException($errorMessage);
104 104
         }
105 105
 
106
-        return "{$type['idPrefix']}x{$entityID}";
106
+        return "{$type[ 'idPrefix' ]}x{$entityID}";
107 107
     }
108 108
 }
Please login to merge, or discard this patch.
src/WSException.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
     }
63 63
     
64 64
     /**
65
-    * Retrieve an external iterator
66
-    *
67
-    * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
68
-    * @return \Traversable
69
-    *  An instance of an object implementing \Traversable
70
-    */
65
+     * Retrieve an external iterator
66
+     *
67
+     * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
68
+     * @return \Traversable
69
+     *  An instance of an object implementing \Traversable
70
+     */
71 71
     public function getIterator()
72 72
     {
73 73
         $properties = $this->getAllProperties();
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
     }
78 78
     
79 79
     /**
80
-    * Get all the properties of the object
81
-    *
82
-    * @return array
83
-    */
80
+     * Get all the properties of the object
81
+     *
82
+     * @return array
83
+     */
84 84
     private function getAllProperties()
85 85
     {
86 86
         $allProperties = get_object_vars($this);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     // custom string representation of object
59 59
     public function __toString()
60 60
     {
61
-        return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
61
+        return __CLASS__.": [{$this->code}]: {$this->message}\n";
62 62
     }
63 63
     
64 64
     /**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
             $fullNameComponents = explode("\0", $fullName);
91 91
             $propertyName = array_pop($fullNameComponents);
92 92
             if ($propertyName && isset($value)) {
93
-                $properties[$propertyName] = $value;
93
+                $properties[ $propertyName ] = $value;
94 94
             }
95 95
         }
96 96
         
Please login to merge, or discard this patch.