Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
57.14% |
8 / 14 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CaptchaVerifyController | |
57.14% |
8 / 14 |
|
50.00% |
1 / 2 |
6.97 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| readResponse | |
53.85% |
7 / 13 |
|
0.00% |
0 / 1 |
5.57 | |||
| 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 CaptchaVerifyController extends BaseController |
| 15 | { |
| 16 | private CaptchaService $service; |
| 17 | public function __construct() |
| 18 | { |
| 19 | $this->service = new CaptchaService(); |
| 20 | } |
| 21 | |
| 22 | public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface |
| 23 | { |
| 24 | $requestErrors = ValidationService::validateServerPostRequest($request); |
| 25 | |
| 26 | if (!empty($requestErrors['errors'])) { |
| 27 | return $this->createJsonResponse( |
| 28 | $response, |
| 29 | $requestErrors, |
| 30 | ErrorMessages::get('invalidRequest', $this->language)['statusCode'] |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | $data = $request->getParsedBody(); |
| 35 | $payload = $data['payload'] ?? null; |
| 36 | $result = $this->service->verifySolution($payload); |
| 37 | return is_array($result) && isset($result['errors']) |
| 38 | ? $this->createJsonResponse($response, $result, ErrorMessages::getHighestStatusCode($result['errors'])) |
| 39 | : $this->createJsonResponse($response, $result, 200); |
| 40 | } |
| 41 | } |