Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
6 / 12
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CaptchaChallengeController
50.00% covered (danger)
50.00%
6 / 12
50.00% covered (danger)
50.00%
1 / 2
8.12
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
45.45% covered (danger)
45.45%
5 / 11
0.00% covered (danger)
0.00%
0 / 1
6.60
1<?php
2
3declare(strict_types=1);
4
5namespace BO\Zmscitizenapi\Controllers\Captcha;
6
7use BO\Zmscitizenapi\BaseController;
8use BO\Zmscitizenapi\Localization\ErrorMessages;
9use BO\Zmscitizenapi\Services\Captcha\CaptchaService;
10use BO\Zmscitizenapi\Services\Core\ValidationService;
11use Psr\Http\Message\RequestInterface;
12use Psr\Http\Message\ResponseInterface;
13
14class CaptchaChallengeController 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::validateServerGetRequest($request);
25        if (!empty($requestErrors['errors'])) {
26            return $this->createJsonResponse(
27                $response,
28                $requestErrors,
29                ErrorMessages::get('invalidRequest', $this->language)['statusCode']
30            );
31        }
32
33        $result = $this->service->createChallenge();
34        return is_array($result) && isset($result['errors'])
35            ? $this->createJsonResponse($response, $result, ErrorMessages::getHighestStatusCode($result['errors']))
36            : $this->createJsonResponse($response, $result, 200);
37    }
38}