UrlShortenerOptions::isUrlValidationEnabled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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