ReCaptchaConfigurationPolicy::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 2
rs 10
c 1
b 0
f 0
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