Lines
88.88%
8 / 9
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AppointmentUpdateController | 88.88% | 8 / 9 | 50.00% | 1 / 2 | 5.03 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| readResponse | 87.50% | 7 / 8 | 0.00% | 0 / 1 | 4.03 | |||||
| 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\AppointmentUpdateService; | |
| 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 AppointmentUpdateController extends BaseController | |
| 16 | { | |
| 17 | private AppointmentUpdateService $service; | |
| 18 | /** @psalm-api */ | |
| 19 | public function __construct() | |
| 20 | { | |
| 21 | $this->service = new AppointmentUpdateService(); | |
| 22 | } | |
| 23 | ||
| 24 | #[\Override] | |
| 25 | public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface | |
| 26 | { | |
| 27 | $requestErrors = ValidationService::validateServerPostRequest($request); | |
| 28 | if (!empty($requestErrors['errors'])) { | |
| 29 | return $this->createJsonResponse($response, $requestErrors, ErrorMessages::get('invalidRequest')['statusCode']); | |
| 30 | } | |
| 31 | ||
| 32 | $authenticatedUser = AuthenticationService::getAuthenticatedUser($request); | |
| 33 | $result = $this->service->processUpdate($request->getParsedBody(), $authenticatedUser); | |
| 34 | return is_array($result) && isset($result['errors']) | |
| 35 | ? $this->createJsonResponse($response, $result, ErrorMessages::getHighestStatusCode($result['errors'])) | |
| 36 | : $this->createJsonResponse($response, $result->toArray(), 200); | |
| 37 | } | |
| 38 | } |