InformationGuesser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\InformationGuesser;
4
5
use Symfony\Component\HttpFoundation\RequestStack;
6
7
/**
8
 * This information guesser, is finding client ip and hostname
9
 *
10
 * @author Yann Eugoné <[email protected]>
11
 */
12
class InformationGuesser implements InformationGuesserInterface
13
{
14
    /**
15
     * @var RequestStack
16
     */
17
    private $requestStack;
18
19
    /**
20
     * @param RequestStack $requestStack The request stack
21
     */
22 2
    public function __construct(RequestStack $requestStack)
23
    {
24 2
        $this->requestStack = $requestStack;
25 2
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30 2
    public function get()
31
    {
32 2
        $request = $this->requestStack->getMasterRequest();
33 2
        if (!$request) {
34 1
            return [];
35
        }
36
37
        return [
38 1
            'ip' => $request->getClientIp(),
39 1
            'host' => gethostname(),
40
        ];
41
    }
42
}
43