UrlShortenerOptions   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 13
dl 0
loc 43
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A isUrlValidationEnabled() 0 3 1
A setValidateUrl() 0 3 1
A redirectCacheLifetime() 0 3 1
A redirectStatusCode() 0 3 1
A normalizeRedirectStatusCode() 0 3 2
A setRedirectCacheLifetime() 0 5 2
A setRedirectStatusCode() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Options;
6
7
use Laminas\Stdlib\AbstractOptions;
8
9
use function Functional\contains;
10
11
use const Shlinkio\Shlink\Core\DEFAULT_REDIRECT_CACHE_LIFETIME;
0 ignored issues
show
Bug introduced by
The constant Shlinkio\Shlink\Core\DEF...REDIRECT_CACHE_LIFETIME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
12
use const Shlinkio\Shlink\Core\DEFAULT_REDIRECT_STATUS_CODE;
0 ignored issues
show
Bug introduced by
The constant Shlinkio\Shlink\Core\DEFAULT_REDIRECT_STATUS_CODE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
13
14
class UrlShortenerOptions extends AbstractOptions
15
{
16
    protected $__strictMode__ = false; // phpcs:ignore
17
18
    private bool $validateUrl = true;
19
    private int $redirectStatusCode = DEFAULT_REDIRECT_STATUS_CODE;
20
    private int $redirectCacheLifetime = DEFAULT_REDIRECT_CACHE_LIFETIME;
21
22 4
    public function isUrlValidationEnabled(): bool
23
    {
24 4
        return $this->validateUrl;
25
    }
26
27 6
    protected function setValidateUrl(bool $validateUrl): void
28
    {
29 6
        $this->validateUrl = $validateUrl;
30 6
    }
31
32 14
    public function redirectStatusCode(): int
33
    {
34 14
        return $this->redirectStatusCode;
35
    }
36
37 7
    protected function setRedirectStatusCode(int $redirectStatusCode): void
38
    {
39 7
        $this->redirectStatusCode = $this->normalizeRedirectStatusCode($redirectStatusCode);
40 7
    }
41
42 7
    private function normalizeRedirectStatusCode(int $statusCode): int
43
    {
44 7
        return contains([301, 302], $statusCode) ? $statusCode : DEFAULT_REDIRECT_STATUS_CODE;
45
    }
46
47 3
    public function redirectCacheLifetime(): int
48
    {
49 3
        return $this->redirectCacheLifetime;
50
    }
51
52 7
    protected function setRedirectCacheLifetime(int $redirectCacheLifetime): void
53
    {
54 7
        $this->redirectCacheLifetime = $redirectCacheLifetime > 0
55 5
            ? $redirectCacheLifetime
56 2
            : DEFAULT_REDIRECT_CACHE_LIFETIME;
57 7
    }
58
}
59