ReCaptchaPolicy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A approvesRequest() 0 3 1
A getGeneratedResponse() 0 3 1
A getApiResponse() 0 3 1
A __construct() 0 4 1
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