Completed
Push — master ( 1de050...162d05 )
by Alejandro
46:23 queued 09:21
created

Visitor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Core\Model;
5
6
use Psr\Http\Message\ServerRequestInterface;
7
8
final class Visitor
9
{
10
    public const REMOTE_ADDRESS_ATTR = 'remote_address';
11
12
    /**
13
     * @var string
14
     */
15
    private $userAgent;
16
    /**
17
     * @var string
18
     */
19
    private $referer;
20
    /**
21
     * @var string|null
22
     */
23
    private $remoteAddress;
24
25 4
    public function __construct(string $userAgent, string $referer, ?string $remoteAddress)
26
    {
27 4
        $this->userAgent = $userAgent;
28 4
        $this->referer = $referer;
29 4
        $this->remoteAddress = $remoteAddress;
30 4
    }
31
32 2
    public static function fromRequest(ServerRequestInterface $request): self
33
    {
34 2
        return new self(
35 2
            $request->getHeaderLine('User-Agent'),
36 2
            $request->getHeaderLine('Referer'),
37 2
            $request->getAttribute(self::REMOTE_ADDRESS_ATTR)
38
        );
39
    }
40
41 1
    public static function emptyInstance(): self
42
    {
43 1
        return new self('', '', null);
44
    }
45
46 2
    public function getUserAgent(): string
47
    {
48 2
        return $this->userAgent;
49
    }
50
51 2
    public function getReferer(): string
52
    {
53 2
        return $this->referer;
54
    }
55
56 2
    public function getRemoteAddress(): ?string
57
    {
58 2
        return $this->remoteAddress;
59
    }
60
}
61