Completed
Pull Request — develop (#645)
by Alejandro
05:15
created

ShortUrlIdentifier   A

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
eloc 16
c 1
b 0
f 0
dl 0
loc 43
rs 10
ccs 19
cts 19
cp 1
wmc 6

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 47
    public function __construct(string $shortCode, ?string $domain = null)
16
    {
17 47
        $this->shortCode = $shortCode;
18 47
        $this->domain = $domain;
19
    }
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 11
    public static function fromRedirectRequest(ServerRequestInterface $request): self
30
    {
31 11
        $shortCode = $request->getAttribute('shortCode', '');
32 11
        $domain = $request->getUri()->getAuthority();
33
34 11
        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 16
    public function shortCode(): string
46
    {
47 16
        return $this->shortCode;
48
    }
49
50 13
    public function domain(): ?string
51
    {
52 13
        return $this->domain;
53
    }
54
}
55