Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
AppointmentByIdController
88.89% covered (warning)
88.89%
8 / 9
50.00% covered (danger)
50.00%
1 / 2
5.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 readResponse
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
4.03
1<?php
2
3declare(strict_types=1);
4
5namespace BO\Zmscitizenapi\Controllers\Appointment;
6
7use BO\Zmscitizenapi\BaseController;
8use BO\Zmscitizenapi\Utils\ErrorMessages;
9use BO\Zmscitizenapi\Services\Appointment\AppointmentByIdService;
10use BO\Zmscitizenapi\Services\Core\AuthenticationService;
11use BO\Zmscitizenapi\Services\Core\ValidationService;
12use Psr\Http\Message\RequestInterface;
13use Psr\Http\Message\ResponseInterface;
14
15class 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        return is_array($result) && isset($result['errors'])
36            ? $this->createJsonResponse($response, $result, ErrorMessages::getHighestStatusCode($result['errors']))
37            : $this->createJsonResponse($response, $result->toArray(), 200);
38    }
39}