Passed
Push — master ( b9ec9d...aca344 )
by Jesús
03:37
created

StockTickerConfig::createWith()   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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chemaclass\StockTicker;
6
7
final class StockTickerConfig implements StockTickerConfigInterface
8
{
9
    private string $templatesDir;
10
11
    private array $env;
12
13 2
    public static function empty(): self
14
    {
15 2
        return new self('', []);
16
    }
17
18 11
    public static function createWith(string $templatesDir, array $env): self
19
    {
20 11
        return new self($templatesDir, $env);
21
    }
22
23 13
    private function __construct(string $templatesDir, array $env)
24
    {
25 13
        $this->templatesDir = $templatesDir;
26 13
        $this->env = $env;
27 13
    }
28
29 1
    public function getTemplatesDir(): string
30
    {
31 1
        return $this->templatesDir;
32
    }
33
34 1
    public function getToAddress(): string
35
    {
36 1
        return $this->env['TO_ADDRESS'];
37
    }
38
39 1
    public function getMailerUsername(): string
40
    {
41 1
        return $this->env['MAILER_USERNAME'];
42
    }
43
44 1
    public function getMailerPassword(): string
45
    {
46 1
        return $this->env['MAILER_PASSWORD'];
47
    }
48
49 1
    public function getSlackDestinyChannelId(): string
50
    {
51 1
        return $this->env['SLACK_DESTINY_CHANNEL_ID'];
52
    }
53
54 1
    public function getSlackBotUserOauthAccessToken(): string
55
    {
56 1
        return $this->env['SLACK_BOT_USER_OAUTH_ACCESS_TOKEN'];
57
    }
58
59 6
    public function isDebug(): bool
60
    {
61 6
        return $this->isTrue($this->env['DEBUG'] ?? null);
62
    }
63
64 6
    private function isTrue(?string $bool): bool
65
    {
66 6
        return in_array($bool, ['true', '1', 'yes'], true);
67
    }
68
}
69