RecaptchaValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 30
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isValid() 0 5 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