ReCaptchaPolicy::getApiResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace WebTheory\Saveyour\Auth\Policy;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use ReCaptcha\ReCaptcha;
7
use ReCaptcha\Response;
8
use WebTheory\HttpPolicy\ServerRequestPolicyInterface;
9
use WebTheory\Saveyour\Http\Request;
10
11
class ReCaptchaPolicy implements ServerRequestPolicyInterface
12
{
13
    protected string $response;
14
15
    protected ReCaptcha $reCaptcha;
16
17 9
    public function __construct(string $response, ReCaptcha $reCaptcha)
18
    {
19 9
        $this->response = $response;
20 9
        $this->reCaptcha = $reCaptcha;
21
    }
22
23 6
    public function approvesRequest(ServerRequestInterface $request): bool
24
    {
25 6
        return $this->getApiResponse($request)->isSuccess();
26
    }
27
28 6
    protected function getApiResponse(ServerRequestInterface $request): Response
29
    {
30 6
        return $this->reCaptcha->verify($this->getGeneratedResponse($request));
31
    }
32
33 6
    protected function getGeneratedResponse(ServerRequestInterface $request): string
34
    {
35 6
        return Request::var($request, $this->response);
0 ignored issues
show
Bug Best Practice introduced by
The expression return WebTheory\Saveyou...quest, $this->response) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
36
    }
37
}
38