Lines
93.33%
14 / 15
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AppointmentByIdController | 93.33% | 14 / 15 | 50.00% | 1 / 2 | 5.01 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| readResponse | 92.85% | 13 / 14 | 0.00% | 0 / 1 | 4.01 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace BO\Zmscitizenapi\Controllers\Appointment; | |
| 6 | ||
| 7 | use BO\Zmscitizenapi\BaseController; | |
| 8 | use BO\Zmscitizenapi\Utils\ErrorMessages; | |
| 9 | use BO\Zmscitizenapi\Services\Appointment\AppointmentByIdService; | |
| 10 | use BO\Zmscitizenapi\Services\Core\AuthenticationService; | |
| 11 | use BO\Zmscitizenapi\Services\Core\ValidationService; | |
| 12 | use Psr\Http\Message\RequestInterface; | |
| 13 | use Psr\Http\Message\ResponseInterface; | |
| 14 | ||
| 15 | class AppointmentByIdController extends BaseController | |
| 16 | { | |
| 17 | private AppointmentByIdService $service; | |
| 18 | /** @psalm-api */ | |
| 19 | public function __construct() | |
| 20 | { | |
| 21 | $this->service = new AppointmentByIdService(); | |
| 22 | } | |
| 23 | ||
| 24 | #[\Override] | |
| 25 | public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface | |
| 26 | { | |
| 27 | ||
| 28 | $requestErrors = ValidationService::validateServerGetRequest($request); | |
| 29 | if (!empty($requestErrors['errors'])) { | |
| 30 | return $this->createJsonResponse($response, $requestErrors, ErrorMessages::get('invalidRequest')['statusCode']); | |
| 31 | } | |
| 32 | ||
| 33 | $authenticatedUser = AuthenticationService::getAuthenticatedUser($request); | |
| 34 | $result = $this->service->getAppointmentById($request->getQueryParams(), $authenticatedUser); | |
| 35 | if (is_array($result) && isset($result['errors'])) { | |
| 36 | return $this->createJsonResponse( | |
| 37 | $response, | |
| 38 | $result, | |
| 39 | ErrorMessages::getHighestStatusCode($result['errors']) | |
| 40 | ); | |
| 41 | } | |
| 42 | ||
| 43 | $payload = $result->toArray(); | |
| 44 | $payload['placeholderEmail'] = \App::getPlaceholderEmail(); | |
| 45 | ||
| 46 | return $this->createJsonResponse($response, $payload, 200); | |
| 47 | } | |
| 48 | } |