ShortUrlIdentifier   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
dl 0
loc 43
ccs 20
cts 20
cp 1
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromCli() 0 6 1
A fromApiRequest() 0 6 1
A __construct() 0 4 1
A fromRedirectRequest() 0 6 1
A shortCode() 0 3 1
A domain() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Model;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use Symfony\Component\Console\Input\InputInterface;
9
10
final class ShortUrlIdentifier
11
{
12
    private string $shortCode;
13
    private ?string $domain;
14
15 62
    public function __construct(string $shortCode, ?string $domain = null)
16
    {
17 62
        $this->shortCode = $shortCode;
18 62
        $this->domain = $domain;
19 62
    }
20
21 7
    public static function fromApiRequest(ServerRequestInterface $request): self
22
    {
23 7
        $shortCode = $request->getAttribute('shortCode', '');
24 7
        $domain = $request->getQueryParams()['domain'] ?? null;
25
26 7
        return new self($shortCode, $domain);
27
    }
28
29 23
    public static function fromRedirectRequest(ServerRequestInterface $request): self
30
    {
31 23
        $shortCode = $request->getAttribute('shortCode', '');
32 23
        $domain = $request->getUri()->getAuthority();
33
34 23
        return new self($shortCode, $domain);
35
    }
36
37 12
    public static function fromCli(InputInterface $input): self
38
    {
39 12
        $shortCode = $input->getArguments()['shortCode'] ?? '';
40 12
        $domain = $input->getOptions()['domain'] ?? null;
41
42 12
        return new self($shortCode, $domain);
43
    }
44
45 18
    public function shortCode(): string
46
    {
47 18
        return $this->shortCode;
48
    }
49
50 16
    public function domain(): ?string
51
    {
52 16
        return $this->domain;
53
    }
54
}
55