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

Visitor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromRequest() 0 8 1
A emptyInstance() 0 4 1
A getUserAgent() 0 4 1
A getReferer() 0 4 1
A getRemoteAddress() 0 4 1
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