Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
OfficeListByServiceService | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
getOfficeList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
extractClientData | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
validateClientData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOfficeListByService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace BO\Zmscitizenapi\Services\Office; |
6 | |
7 | use BO\Zmscitizenapi\Models\Collections\OfficeList; |
8 | use BO\Zmscitizenapi\Services\Core\ValidationService; |
9 | use BO\Zmscitizenapi\Services\Core\ZmsApiFacadeService; |
10 | |
11 | class OfficeListByServiceService |
12 | { |
13 | public function getOfficeList(array $queryParams, bool $showUnpublished = false): OfficeList|array |
14 | { |
15 | $clientData = $this->extractClientData($queryParams); |
16 | $errors = $this->validateClientData($clientData); |
17 | if (!empty($errors['errors'])) { |
18 | return $errors; |
19 | } |
20 | |
21 | return $this->getOfficeListByService($clientData, $showUnpublished); |
22 | } |
23 | |
24 | private function extractClientData(array $queryParams): object |
25 | { |
26 | return (object) [ |
27 | 'serviceId' => isset($queryParams['serviceId']) && is_numeric($queryParams['serviceId']) |
28 | ? (int) $queryParams['serviceId'] |
29 | : null |
30 | ]; |
31 | } |
32 | |
33 | private function validateClientData(object $data): array |
34 | { |
35 | return ValidationService::validateGetOfficeListByServiceId($data->serviceId); |
36 | } |
37 | |
38 | private function getOfficeListByService(object $data, bool $showUnpublished = false): array|OfficeList |
39 | { |
40 | return ZmsApiFacadeService::getOfficeListByServiceId($data->serviceId, $showUnpublished); |
41 | } |
42 | } |