Passed
Push — master ( 8f669d...12a285 )
by Dmitrii
01:40 queued 10s
created

IpResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 17
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveIp() 0 7 2
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Karser\Recaptcha3Bundle\Services;
4
5
use Symfony\Component\HttpFoundation\RequestStack;
6
7
final class IpResolver implements IpResolverInterface
8
{
9
    /** @var RequestStack */
10
    private $requestStack;
11
12
    public function __construct(RequestStack $requestStack)
13
    {
14
        $this->requestStack = $requestStack;
15
    }
16
17
    public function resolveIp(): ?string
18
    {
19
        $request = $this->requestStack->getCurrentRequest();
20
        if ($request === null) {
21
            return null;
22
        }
23
        return $request->getClientIp();
24
    }
25
}
26