Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| ServiceListByOfficeService | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
| getServiceList | |
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 | |||
| getServicesByOffice | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace BO\Zmscitizenapi\Services\Service; |
| 6 | |
| 7 | use BO\Zmscitizenapi\Models\Collections\ServiceList; |
| 8 | use BO\Zmscitizenapi\Services\Core\ValidationService; |
| 9 | use BO\Zmscitizenapi\Services\Core\ZmsApiFacadeService; |
| 10 | |
| 11 | class ServiceListByOfficeService |
| 12 | { |
| 13 | public function getServiceList(array $queryParams, bool $showUnpublished = false): ServiceList|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->getServicesByOffice($clientData, $showUnpublished); |
| 22 | } |
| 23 | |
| 24 | private function extractClientData(array $queryParams): object |
| 25 | { |
| 26 | return (object) [ |
| 27 | 'officeId' => isset($queryParams['officeId']) && is_numeric($queryParams['officeId']) |
| 28 | ? (int) $queryParams['officeId'] |
| 29 | : null |
| 30 | ]; |
| 31 | } |
| 32 | |
| 33 | private function validateClientData(object $clientData): array |
| 34 | { |
| 35 | return ValidationService::validateGetServicesByOfficeId($clientData->officeId); |
| 36 | } |
| 37 | |
| 38 | private function getServicesByOffice(object $clientData, bool $showUnpublished = false): array|ServiceList |
| 39 | { |
| 40 | return ZmsApiFacadeService::getServicesByOfficeId($clientData->officeId, $showUnpublished); |
| 41 | } |
| 42 | } |