Lines 100.00% 11 / 11
Methods 100.00% 3 / 3
Classes 100.00% 1 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 getNoReplyEmail 100.00% 4 / 4 100.00% 1 / 1 3
 getProvider 100.00% 6 / 6 100.00% 1 / 1 2
24readonly class MailSettings
25{
26    private const string DEFAULT_PROVIDER = 'smtp';
27    private const array ALLOWED_PROVIDERS = ['smtp', 'sendgrid', 'ses', 'mailgun'];
28
29    public function __construct(
30        private CoreConfiguration $coreConfiguration,
31    ) {
32    }
33
34    public function getNoReplyEmail(): string
35    {
36        $sender = $this->coreConfiguration->get(item: 'mail.noReplySenderAddress');
37        if ($sender === '' || $sender === null) {
38            return (string) $this->coreConfiguration->get(item: 'main.administrationMail');
39        }
40
41        return (string) $sender;
42    }
43
44    public function getProvider(): string
45    {
46        $provider = strtolower(
47            (string) ($this->coreConfiguration->get(item: 'mail.provider') ?? self::DEFAULT_PROVIDER),
48        );
49
50        if (!in_array($provider, self::ALLOWED_PROVIDERS, strict: true)) {
51            return self::DEFAULT_PROVIDER;
52        }
53
54        return $provider;
55    }
56}