Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| MailSettings | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
6 | |
100.00% |
1 / 1 |
| __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 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The mail settings class |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2025-2026 phpMyFAQ Team |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @link https://www.phpmyfaq.de |
| 15 | * @since 2025-11-03 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Configuration; |
| 21 | |
| 22 | use phpMyFAQ\Configuration as CoreConfiguration; |
| 23 | |
| 24 | readonly 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 | } |