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