Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
AppointmentByIdService | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
10 | |
100.00% |
1 / 1 |
getAppointmentById | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
extractClientData | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
6 | |||
validateClientData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAppointment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace BO\Zmscitizenapi\Services\Appointment; |
6 | |
7 | use BO\Zmscitizenapi\Models\ThinnedProcess; |
8 | use BO\Zmscitizenapi\Services\Core\ValidationService; |
9 | use BO\Zmscitizenapi\Services\Core\ZmsApiFacadeService; |
10 | |
11 | class AppointmentByIdService |
12 | { |
13 | public function getAppointmentById(array $queryParams): ThinnedProcess|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->getAppointment($clientData->processId, $clientData->authKey); |
22 | } |
23 | |
24 | private function extractClientData(array $queryParams): object |
25 | { |
26 | return (object) [ |
27 | 'processId' => isset($queryParams['processId']) && is_numeric($queryParams['processId']) |
28 | ? (int) $queryParams['processId'] |
29 | : null, |
30 | 'authKey' => isset($queryParams['authKey']) && is_string($queryParams['authKey']) && trim($queryParams['authKey']) !== '' |
31 | ? htmlspecialchars(trim($queryParams['authKey']), ENT_QUOTES, 'UTF-8') |
32 | : null |
33 | ]; |
34 | } |
35 | |
36 | private function validateClientData(object $data): array |
37 | { |
38 | return ValidationService::validateGetProcessById($data->processId, $data->authKey); |
39 | } |
40 | |
41 | private function getAppointment(?int $processId, ?string $authKey): ThinnedProcess|array |
42 | { |
43 | return ZmsApiFacadeService::getThinnedProcessById($processId, $authKey); |
44 | } |
45 | } |