RecaptchaValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Acelaya\Website\Form;
5
6
use ReCaptcha\ReCaptcha;
7
use Zend\Validator\AbstractValidator;
8
use Zend\Validator\Exception;
9
10
class RecaptchaValidator extends AbstractValidator
11
{
12
    /**
13
     * @var ReCaptcha
14
     */
15 7
    protected $recaptcha;
16
17 7
    public function __construct(ReCaptcha $recaptcha)
18 7
    {
19 7
        parent::__construct();
20
        $this->recaptcha = $recaptcha;
21
    }
22
23
    /**
24
     * Returns true if and only if $value meets the validation requirements
25
     *
26
     * If $value fails validation, then this method returns false, and
27
     * getMessages() will return an array of messages that explain why the
28
     * validation failed.
29
     *
30
     * @param  mixed $value
31
     * @return bool
32 3
     * @throws Exception\RuntimeException If validation of $value is impossible
33
     */
34 3
    public function isValid($value): bool
35 3
    {
36
        $resp = $this->recaptcha->verify($value);
37
        return $resp->isSuccess();
38
    }
39
}
40