Action   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 4
1
<?php
2
/**
3
 * Copyright (c) 2019. Volodymyr Hryvinskyi.  All rights reserved.
4
 * @author: <mailto:[email protected]>
5
 * @github: <https://github.com/hryvinskyi>
6
 */
7
8
declare(strict_types=1);
9
10
namespace Hryvinskyi\InvisibleCaptcha\Model\ReCaptcha\Validators;
11
12
use Hryvinskyi\InvisibleCaptcha\Model\ReCaptcha\Response;
13
use Hryvinskyi\InvisibleCaptcha\Model\ReCaptcha\VerifyReCaptcha;
14
15
/**
16
 * Class Action
17
 */
18
class Action implements ValidatorInterface
19
{
20
    /**
21
     * Expected action did not match
22
     *
23
     * @const string
24
     */
25
    const E_ACTION_MISMATCH = 'action-mismatch';
26
27
    /**
28
     * @param VerifyReCaptcha $verify
29
     * @param Response $response
30
     *
31
     * @return string|null
32
     */
33
    public function validate(VerifyReCaptcha $verify, Response $response): ?string
34
    {
35
        if (
36
            $verify->getExpectedAction()
37
            && $response->getAction()
38
            && strcasecmp($verify->getExpectedAction(), $response->getAction()) !== 0
39
        ) {
40
            return self::E_ACTION_MISMATCH;
41
        }
42
43
        return null;
44
    }
45
}
46