Completed
Pull Request — master (#19)
by Łukasz
07:12
created

Config::getServerHost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tworzenieweb\SqlProvisioner\Config;
4
5
use Dotenv\Dotenv;
6
7
class Config
8
{
9
    const MANDATORY_ENV_VARIABLES = [
10
        self::SMTP_USER,
11
        self::SMTP_PASSWORD,
12
        self::SMTP_HOST,
13
        self::EMAIL_SUBJECT,
14
        self::FROM_EMAIL,
15
    ];
16
    const SMTP_USER = 'SMTP_USER';
17
    const SMTP_PASSWORD = 'SMTP_PASSWORD';
18
    const SMTP_HOST = 'SMTP_HOST';
19
    const EMAIL_SUBJECT = 'EMAIL_SUBJECT';
20
    const FROM_EMAIL = 'FROM_EMAIL';
21
    const FROM_NAME = 'FROM_NAME';
22
    const TO_EMAILS = 'TO_EMAILS';
23
    const SERVER_HOST = 'SERVER_HOST';
24
25
26
27
    public function __construct(string $path)
28
    {
29
        $loader = new Dotenv($path);
30
        $loader->load();
31
        $loader->required(self::MANDATORY_ENV_VARIABLES)->notEmpty();
32
    }
33
34
35
36
    public function getSmtpUsername(): string
37
    {
38
        return $_ENV[self::SMTP_USER];
39
    }
40
41
42
43
    public function getSmtpPassword(): string
44
    {
45
        return $_ENV[self::SMTP_PASSWORD];
46
    }
47
48
49
50
    public function getSmtpHost(): string
51
    {
52
        return $_ENV[self::SMTP_HOST];
53
    }
54
55
56
57
    public function getEmailSubject(): string
58
    {
59
        return sprintf($_ENV[self::EMAIL_SUBJECT], $this->getServerHost());
60
    }
61
62
63
64
    public function getFromEmail(): string
65
    {
66
        return $_ENV[self::FROM_EMAIL];
67
    }
68
69
70
71
    public function getFromName(): string
72
    {
73
        return $_ENV[self::FROM_NAME];
74
    }
75
76
77
78
    public function getRecipientsList(): array
79
    {
80
        return explode(',', $_ENV[self::TO_EMAILS]);
81
    }
82
83
84
85
    public function getServerHost(): string
86
    {
87
        return $_ENV[self::SERVER_HOST];
88
    }
89
}