IpResolver::resolveIp()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
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 5
    public function __construct(RequestStack $requestStack)
13
    {
14 5
        $this->requestStack = $requestStack;
15 5
    }
16
17 4
    public function resolveIp(): ?string
18
    {
19 4
        $request = $this->requestStack->getCurrentRequest();
20 4
        if ($request === null) {
21 2
            return null;
22
        }
23 2
        return $request->getClientIp();
24
    }
25
}
26