ReCaptchaConfigurationPolicy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 28
ccs 0
cts 15
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A create() 0 9 1
1
<?php
2
3
namespace WebTheory\Saveyour\Auth\Policy;
4
5
use ReCaptcha\ReCaptcha;
6
use WebTheory\HttpPolicy\ServerRequestPolicyInterface;
7
8
class ReCaptchaConfigurationPolicy extends ReCaptchaPolicy implements ServerRequestPolicyInterface
9
{
10
    public function __construct(
11
        string $response,
12
        string $secret,
13
        string $hostName,
14
        string $action,
15
        ?float $minScore = 0.5,
16
        ?int $timeout = null
17
    ) {
18
        $this->response = $response;
19
        $this->reCaptcha = $reCaptcha = new ReCaptcha($secret);
20
21
        $reCaptcha->setExpectedAction($action);
22
        $reCaptcha->setScoreThreshold($minScore);
23
        $reCaptcha->setExpectedHostname($hostName);
24
        $reCaptcha->setChallengeTimeout($timeout);
25
    }
26
27
    public static function create(array $config): ReCaptchaConfigurationPolicy
28
    {
29
        return new static(
30
            $config['response'],
31
            $config['secret'],
32
            $config['host_name'],
33
            $config['action'],
34
            $config['min_score'] ?? 0.5,
35
            $config['timeout'] ?? null
36
        );
37
    }
38
}
39