Passed
Push — main ( 8deca5...10c92c )
by Daniel
14:13
created

ConfigProvider::getTokenLifetime()   A

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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Config;
6
7
use Configula\ConfigValues;
8
use Psr\Log\LogLevel;
9
10
final class ConfigProvider implements ConfigProviderInterface
11
{
12 15
    public function __construct(
13
        private readonly ConfigValues $configValues,
14
    ) {
15
    }
16
17 1
    public function getLogFilePath(): string
18
    {
19 1
        return $this->configValues->get('logging.path', '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...get('logging.path', '') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
20
    }
21
22 1
    public function getJwtSecret(): string
23
    {
24 1
        return $this->configValues->get('security.jwt_secret', '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...curity.jwt_secret', '') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
25
    }
26
27 1
    public function getCookieName(): string
28
    {
29 1
        return $this->configValues->get('security.token_name', 'nekot');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...y.token_name', 'nekot') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
30
    }
31
32 1
    public function getTokenLifetime(): int
33
    {
34 1
        return (int) $this->configValues->get('security.token_lifetime', 1_086_400);
0 ignored issues
show
Bug introduced by
The constant Uxmp\Core\Component\Config\1_086_400 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
35
    }
36
37 1
    public function getLogLevel(): string
38
    {
39 1
        return $this->configValues->get('logging.level', LogLevel::ERROR);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...sr\Log\LogLevel::ERROR) could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
40
    }
41
42 1
    public function getCorsOrigin(): string
43
    {
44 1
        return $this->configValues->get('http.cors_origin', '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...'http.cors_origin', '') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
45
    }
46
47 4
    public function getApiBasePath(): string
48
    {
49 4
        return $this->configValues->get('http.api_base_path', '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...ttp.api_base_path', '') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
50
    }
51
52 1
    public function getAssetPath(): string
53
    {
54 1
        return $this->configValues->get('assets.path', '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...>get('assets.path', '') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
55
    }
56
57 1
    public function getDebugMode(): bool
58
    {
59 1
        return (bool) $this->configValues->get('debug.enabled', false);
60
    }
61
62 1
    public function getDatabaseDsn(): string
63
    {
64 1
        return $this->configValues->get('database.dsn', '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...get('database.dsn', '') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
65
    }
66
67 1
    public function getDatabasePassword(): string
68
    {
69 1
        return $this->configValues->get('database.password', '');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->configValu...database.password', '') could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
70
    }
71
72 3
    public function getBaseUrl(): string
73
    {
74 3
        $hostname = $this->configValues->get('http.hostname', '');
75 3
        $port = (int) $this->configValues->get('http.port', 0);
76 3
        $ssl = ((bool) $this->configValues->get('http.ssl', true)) === true;
77
78 3
        $protocol = ($ssl === true)
79 2
            ? 'https'
80 1
            : 'http';
81
82 3
        $port_string = '';
83
        if (
84 3
            $port !== 0 &&
85 3
            !in_array($port, [80, 443], true)
86
        ) {
87 1
            $port_string = sprintf(':%d', $port);
88
        }
89
90 3
        return sprintf(
91
            '%s://%s%s%s',
92
            $protocol,
93
            $hostname,
0 ignored issues
show
Bug introduced by
It seems like $hostname can also be of type array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
            /** @scrutinizer ignore-type */ $hostname,
Loading history...
94
            $port_string,
95 3
            $this->getApiBasePath()
96
        );
97
    }
98
99 1
    public function getClientCacheMaxAge(): int
100
    {
101 1
        return 86400 * 100;
102
    }
103
}
104