Passed
Push — master ( dbbcdc...ae2f61 )
by Volodymyr
07:12
created

Host::validate()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 11
rs 10
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 Host
17
 */
18
class Host implements ValidatorInterface
19
{
20
    /**
21
     * Expected hostname did not match
22
     *
23
     * @const string
24
     */
25
    const E_HOSTNAME_MISMATCH = 'hostname-mismatch';
26
27
    /**
28
     * Verify hostname
29
     *
30
     * @param VerifyReCaptcha $verify
31
     * @param Response $response
32
     *
33
     * @return string
34
     */
35
    public function validate(VerifyReCaptcha $verify, Response $response): ?string
36
    {
37
        if (
38
            $verify->getExpectedHostname()
39
            && $response->getHostname()
40
            && strcasecmp($verify->getExpectedHostname(), $response->getHostname()) !== 0
41
        ) {
42
            return self::E_HOSTNAME_MISMATCH;
43
        }
44
45
        return null;
46
    }
47
}
48