Passed
Pull Request — master (#5)
by Rafal
02:30
created

Config   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 21
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getClientSecret() 0 10 2
A getClientId() 0 10 2
A getRedirectUri() 0 10 2
A getSpotifyUsername() 0 10 2
1
<?php declare(strict_types=1);
2
3
namespace SpotifyApiConnect\Domain\Model;
4
5
use SpotifyApiConnect\Message;
6
use RuntimeException;
7
8
final class Config implements ConfigInterface
9
{
10
    /**
11
     * @return string
12
     */
13
    public function getClientId(): string
14
    {
15
        $clientId = (string)getenv('CLIENT_ID');
16
        if (empty($clientId)) {
17
            throw new RuntimeException(
18
                sprintf(Message::ERROR_GET_ENV_VARIABLE, 'CLIENT_ID')
19
            );
20
        }
21
22
        return $clientId;
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public function getClientSecret(): string
29
    {
30
        $clientSecret = (string)getenv('CLIENT_SECRET');
31
        if (empty($clientSecret)) {
32
            throw new RuntimeException(
33
                sprintf(Message::ERROR_GET_ENV_VARIABLE, 'CLIENT_SECRET')
34
            );
35
        }
36
37
        return $clientSecret;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getRedirectUri(): string
44
    {
45
        $redirectUri = (string)getenv('REDIRECT_URI');
46
        if (empty($redirectUri)) {
47
            throw new RuntimeException(
48
                sprintf(Message::ERROR_GET_ENV_VARIABLE, 'REDIRECT_URI')
49
            );
50
        }
51
52
        return $redirectUri;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getSpotifyUsername(): string
59
    {
60
        $spotifyUsername = (string)getenv('SPOTIFY_USERNAME');
61
        if (empty($spotifyUsername)) {
62
            throw new RuntimeException(
63
                sprintf(Message::ERROR_GET_ENV_VARIABLE, 'SPOTIFY_USERNAME')
64
            );
65
        }
66
67
        return $spotifyUsername;
68
    }
69
}