Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
76.19% |
16 / 21 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
AvailableAppointmentsListService | |
76.19% |
16 / 21 |
|
80.00% |
4 / 5 |
12.63 | |
0.00% |
0 / 1 |
getAvailableAppointmentsList | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
extractClientData | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 | |||
validateClientData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAvailableAppointments | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAvailableAppointmentsListByOffice | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace BO\Zmscitizenapi\Services\Availability; |
6 | |
7 | use BO\Zmscitizenapi\Models\AvailableAppointments; |
8 | use BO\Zmscitizenapi\Models\AvailableAppointmentsByOffice; |
9 | use BO\Zmscitizenapi\Services\Core\ValidationService; |
10 | use BO\Zmscitizenapi\Services\Core\ZmsApiFacadeService; |
11 | |
12 | class AvailableAppointmentsListService |
13 | { |
14 | public function getAvailableAppointmentsList(array $queryParams): AvailableAppointments|array |
15 | { |
16 | $clientData = $this->extractClientData($queryParams); |
17 | $errors = $this->validateClientData($clientData); |
18 | if (!empty($errors['errors'])) { |
19 | return $errors; |
20 | } |
21 | |
22 | return $this->getAvailableAppointments($clientData); |
23 | } |
24 | |
25 | private function extractClientData(array $queryParams): object |
26 | { |
27 | return (object) [ |
28 | 'date' => isset($queryParams['date']) ? (string) $queryParams['date'] : null, |
29 | 'officeIds' => isset($queryParams['officeId']) |
30 | ? array_map('trim', explode(',', (string) $queryParams['officeId'])) |
31 | : [], |
32 | 'serviceIds' => isset($queryParams['serviceId']) |
33 | ? array_map('trim', explode(',', (string) $queryParams['serviceId'])) |
34 | : [], |
35 | 'serviceCounts' => isset($queryParams['serviceCount']) |
36 | ? array_map('trim', explode(',', (string) $queryParams['serviceCount'])) |
37 | : [] |
38 | ]; |
39 | } |
40 | |
41 | private function validateClientData(object $data): array |
42 | { |
43 | return ValidationService::validateGetAvailableAppointments($data->date, $data->officeIds, $data->serviceIds, $data->serviceCounts); |
44 | } |
45 | |
46 | private function getAvailableAppointments(object $data, ?bool $groupByOffice = false): array|AvailableAppointments|AvailableAppointmentsByOffice |
47 | { |
48 | return ZmsApiFacadeService::getAvailableAppointments($data->date, $data->officeIds, $data->serviceIds, $data->serviceCounts, $groupByOffice); |
49 | } |
50 | |
51 | public function getAvailableAppointmentsListByOffice($queryParams): AvailableAppointmentsByOffice|array |
52 | { |
53 | $clientData = $this->extractClientData($queryParams); |
54 | $errors = $this->validateClientData($clientData); |
55 | if (!empty($errors['errors'])) { |
56 | return $errors; |
57 | } |
58 | |
59 | return $this->getAvailableAppointments($clientData, true); |
60 | } |
61 | } |