@@ -42,7 +42,7 @@ class ApiClient extends \Ease\Sand
4242 public bool $ throwException = true ;
4343
4444 /**
45- * @var array Unit status enumeration
45+ * @var array<int, string> Unit status enumeration
4646 */
4747 public array $ unitStatus = [
4848 0 => 'free ' ,
@@ -54,7 +54,7 @@ class ApiClient extends \Ease\Sand
5454 ];
5555
5656 /**
57- * @var array Unit type enumeration
57+ * @var array<int, string> Unit type enumeration
5858 */
5959 public array $ unitType = [
6060 1 => 'flat ' ,
@@ -95,6 +95,8 @@ class ApiClient extends \Ease\Sand
9595
9696 /**
9797 * Last CURL response info.
98+ *
99+ * @var array<string>
98100 */
99101 private array $ curlInfo = [];
100102
@@ -125,14 +127,8 @@ class ApiClient extends \Ease\Sand
125127
126128 /**
127129 * RealPad Data obtainer.
128- *
129- * @var string - leave empty to use Environment or constant REALPAD_USERNAME
130- * @var string - leave empty to use Environment or constant REALPAD_PASSWORD
131- *
132- * @param mixed $username
133- * @param mixed $password
134130 */
135- public function __construct ($ username = '' , $ password = '' )
131+ public function __construct (string $ username = '' , string $ password = '' )
136132 {
137133 $ this ->apiUsername = \strlen ($ username ) ? $ username : \Ease \Shared::cfg ('REALPAD_USERNAME ' );
138134 $ this ->apiPassword = \strlen ($ password ) ? $ password : \Ease \Shared::cfg ('REALPAD_PASSWORD ' );
@@ -148,6 +144,11 @@ public function __destruct()
148144 $ this ->disconnect ();
149145 }
150146
147+ public function getLastResponse (): string
148+ {
149+ return $ this ->lastCurlResponse ;
150+ }
151+
151152 /**
152153 * Initialize CURL.
153154 *
@@ -206,7 +207,7 @@ public function doCurlRequest($url, $method = 'GET', $postParams = [])
206207 $ this ->lastCurlResponse = curl_exec ($ this ->curl );
207208 $ this ->curlInfo = curl_getinfo ($ this ->curl );
208209 $ this ->curlInfo ['when ' ] = microtime ();
209- $ this ->lastResponseCode = $ this ->curlInfo ['http_code ' ];
210+ $ this ->lastResponseCode = ( int ) $ this ->curlInfo ['http_code ' ];
210211 $ this ->lastCurlError = curl_error ($ this ->curl );
211212
212213 if (\strlen ($ this ->lastCurlError )) {
@@ -224,14 +225,14 @@ public function doCurlRequest($url, $method = 'GET', $postParams = [])
224225 /**
225226 * Curl Error getter.
226227 *
227- * @return string
228+ * @return array< string>
228229 */
229230 public function getErrors ()
230231 {
231- return $ this ->lastCurlError ;
232+ return [ $ this ->lastCurlError ] ;
232233 }
233234
234- public function getLastResponseCode ()
235+ public function getLastResponseCode (): int
235236 {
236237 return $ this ->lastResponseCode ;
237238 }
@@ -307,7 +308,7 @@ public function getResource($uid)
307308 *
308309 * @return int size of saved file in bites
309310 */
310- public function saveResource ($ uid , $ filename )
311+ public function saveResource ($ uid , string $ filename ): int
311312 {
312313 $ resource = $ this ->getResource ($ uid );
313314
@@ -319,10 +320,8 @@ public function saveResource($uid, $filename)
319320 *
320321 * @param string $endpoint suffix
321322 * @param mixed $params
322- *
323- * @return array
324323 */
325- public function getExcelData ($ endpoint , $ params = [])
324+ public function getExcelData ($ endpoint , $ params = []): array
326325 {
327326 $ responseCode = $ this ->doCurlRequest ($ this ->baseEndpoint .'ws/v10/ ' .$ endpoint , 'POST ' , $ params );
328327 $ excelData = [];
@@ -346,10 +345,8 @@ public function getExcelData($endpoint, $params = [])
346345
347346 /**
348347 * Obtain listing of all Customers.
349- *
350- * @return array
351348 */
352- public function listCustomers ()
349+ public function listCustomers (): array
353350 {
354351 return $ this ->getExcelData ('list-excel-customers ' );
355352 }
@@ -359,30 +356,28 @@ public function listCustomers()
359356 * numeric ID of the unit availability, unique project ID and deal ID from
360357 * the Realpad database. See the appendix for the unit type and availability
361358 * enums.
362- *
363- * @return array
364359 */
365- public function listProducts ()
360+ public function listProducts (): array
366361 {
367362 return $ this ->getExcelData ('list-excel-products ' );
368363 }
369364
370365 /**
371366 * The last column contains the unique Deal ID from the Realpad database.
372367 *
373- * @return array
368+ * @return array<int, string>
374369 */
375- public function listBusinessCases ()
370+ public function listBusinessCases (): array
376371 {
377372 return $ this ->getExcelData ('list-excel-business-cases ' );
378373 }
379374
380375 /**
381376 * Obtain listing of all Projects.
382377 *
383- * @return array
378+ * @return array<int, string>
384379 */
385- public function listProjects ()
380+ public function listProjects (): array
386381 {
387382 return $ this ->getExcelData ('list-excel-projects ' );
388383 }
@@ -392,31 +387,27 @@ public function listProjects()
392387 * and sales agent ID from the Realpad database. The first column is the
393388 * relevant deal ID.
394389 *
395- * @return array
390+ * @return array<int, string>
396391 */
397- public function listDealDocuments ()
392+ public function listDealDocuments (): array
398393 {
399394 return $ this ->getExcelData ('list-excel-deal-documents ' );
400395 }
401396
402397 /**
403398 * The last column contains the unique payment ID from the Realpad database.
404399 * The second column is the relevant deal ID.
405- *
406- * @return array
407400 */
408- public function listPaymentsPrescribed ()
401+ public function listPaymentsPrescribed (): array
409402 {
410403 return $ this ->getExcelData ('list-excel-payments-prescribed ' );
411404 }
412405
413406 /**
414407 * The first column contains the unique incoming payment ID from the Realpad
415408 * database. The second column is the relevant Deal ID.
416- *
417- * @return array
418409 */
419- public function listPaymentsIncoming ()
410+ public function listPaymentsIncoming (): array
420411 {
421412 return $ this ->getExcelData ('list-excel-payments-incoming ' );
422413 }
@@ -425,21 +416,17 @@ public function listPaymentsIncoming()
425416 * The last columns contain the additional product ID, its type ID, and the
426417 * ID of the associated prescribed payment from the Realpad database.
427418 * The first column is the relevant deal ID.
428- *
429- * @return array
430419 */
431- public function listAdditionalProducts ()
420+ public function listAdditionalProducts (): array
432421 {
433422 return $ this ->getExcelData ('list-excel-additional-products ' );
434423 }
435424
436425 /**
437426 * Among the columns, there are those representing the deal ID and
438427 * inspection ID from the Realpad database.
439- *
440- * @return array
441428 */
442- public function listInspections ()
429+ public function listInspections (): array
443430 {
444431 return $ this ->getExcelData ('list-excel-inspections ' );
445432 }
@@ -455,18 +442,16 @@ public function listInspections()
455442 *
456443 * @todo Implement Modes
457444 *
458- * @var string mode none or one from: DEAL_DEFECTS,
459- * DEAL_DEFECTS_COMMUNAL_AREA,
460- * DEAL_DEFECTS_COMBINED,
461- * INSPECTION_DEFECTS,
462- * INSPECTION_DEFECTS_COMMUNAL_AREA,
463- * INSPECTION_DEFECTS_COMBINED
445+ * @param string $ mode none or one from: DEAL_DEFECTS,
446+ * DEAL_DEFECTS_COMMUNAL_AREA,
447+ * DEAL_DEFECTS_COMBINED,
448+ * INSPECTION_DEFECTS,
449+ * INSPECTION_DEFECTS_COMMUNAL_AREA,
450+ * INSPECTION_DEFECTS_COMBINED
464451 *
465- * @param mixed $mode
466- *
467- * @return array
452+ * @return array<int, string>
468453 */
469- public function listDefects ($ mode = '' )
454+ public function listDefects (string $ mode = '' ): array
470455 {
471456 $ modesAvailble = [
472457 'DEAL_DEFECTS ' ,
@@ -478,7 +463,7 @@ public function listDefects($mode = '')
478463 ];
479464
480465 if (\strlen ($ mode ) && (array_search ($ mode , $ modesAvailble , true ) === false )) {
481- throw new \SpojeNet \Realpad \Exception ('Iillegal inspection Mode ' .$ mode );
466+ throw new \SpojeNet \Realpad \Exception ('Iillegal inspection Mode ' .$ mode, $ this );
482467 }
483468
484469 return $ this ->getExcelData ('list-excel-defects ' , ['mode ' => $ mode ]);
@@ -488,7 +473,7 @@ public function listDefects($mode = '')
488473 * The last columns contain the task ID, customer ID, and sales agent ID
489474 * from the Realpad database.
490475 *
491- * @return array
476+ * @return array<string, string>
492477 */
493478 public function listTasks ()
494479 {
@@ -499,7 +484,7 @@ public function listTasks()
499484 * The last columns contain the event ID, customer ID, unit, and project ID
500485 * from the Realpad database.
501486 *
502- * @return array
487+ * @return array<string, string>
503488 */
504489 public function listEvents ()
505490 {
@@ -509,7 +494,7 @@ public function listEvents()
509494 /**
510495 * The last column contains the unit ID from the Realpad database.
511496 *
512- * @return array
497+ * @return array<string, string>
513498 */
514499 public function listSalesStatus ()
515500 {
@@ -521,12 +506,12 @@ public function listSalesStatus()
521506 * containing the data on the given row. The second column contains the name
522507 * of the user who caused that data to be recorded.
523508 *
524- * @var int required parameter unitid, which has to be a valid unit
509+ * @param int $unitID required parameter unitid, which has to be a valid unit
525510 * Realpad database ID obtained from some other endpoint
526511 *
527- * @return array
512+ * @return array<string, string>
528513 */
529- public function listUnitHistory (int $ unitID )
514+ public function listUnitHistory (int $ unitID ): array
530515 {
531516 return $ this ->getExcelData ('list-excel-unit-history ' , ['unitid ' => $ unitID ]);
532517 }
@@ -535,24 +520,25 @@ public function listUnitHistory(int $unitID)
535520 * Listing of Invoices. The initial set of columns describes the Invoice
536521 * itself, and the last set of columns contains the data of its Lines.
537522 *
538- * @var array ● `filter_status` - if left empty, invoices in all statuses are sent. 1 - new invoices. 2 -
523+ * @param array<string, string> $options
524+ * ● `filter_status` - if left empty, invoices in all statuses are sent. 1 - new invoices. 2 -
539525 * invoices in Review #1. 3 - invoices in Review #2. 4 - invoices in approval. 5 - fully
540526 * approved invoices. 6 - fully rejected invoices.
541527 *
542- * ● `filter_groupcompany` - if left empty, invoices from all the group companies are sent. If
528+ * ● `filter_groupcompany` - if left empty, invoices from all the group companies are sent. If
543529 * Realpad database IDs of group companies are provided (as a comma-separated list),
544530 * then only invoices from these companies are sent.
545531 *
546- * ● `filter_issued_from` - specify a date in the 2019-12-31 format to only send invoices
532+ * ● `filter_issued_from` - specify a date in the 2019-12-31 format to only send invoices
547533 * issues after that date.
548534 *
549- * ● `filter_issued_to` - specify a date in the 2019-12-31 format to only send invoices issues before that date.
535+ * ● `filter_issued_to` - specify a date in the 2019-12-31 format to only send invoices issues before that date.
550536 *
551- * @param mixed $options
537+ * @throws \SpojeNet\Realpad\Exception
552538 *
553- * @return array
539+ * @return array<string, string>
554540 */
555- public function listInvoices ($ options = [])
541+ public function listInvoices (array $ options = []): array
556542 {
557543 $ colsAvailble = [
558544 'filter_status ' ,
@@ -563,7 +549,7 @@ public function listInvoices($options = [])
563549
564550 foreach ($ options as $ key => $ value ) {
565551 if (array_search ($ key , $ colsAvailble , true ) === false ) {
566- throw new \SpojeNet \Realpad \Exception ('Iillegal Invoice option ' .$ key );
552+ throw new \SpojeNet \Realpad \Exception ('Iillegal Invoice option ' .$ key, $ this );
567553 }
568554 }
569555
0 commit comments