Passed
Push — master ( 247a52...f18ab4 )
by Melech
07:21 queued 03:19
created

Config::setPropertiesFromEnv()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 26
rs 9.4888
c 0
b 0
f 0
cc 5
nc 16
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Mail;
15
16
use Valkyrja\Config\Config as ParentConfig;
17
use Valkyrja\Mail\Config\Configurations;
18
use Valkyrja\Mail\Config\DefaultMessageConfiguration;
19
use Valkyrja\Mail\Config\LogConfiguration;
20
use Valkyrja\Mail\Config\MailgunConfiguration;
21
use Valkyrja\Mail\Config\MessageConfigurations;
22
use Valkyrja\Mail\Config\NullConfiguration;
23
use Valkyrja\Mail\Config\PhpMailerConfiguration;
24
use Valkyrja\Mail\Constant\ConfigName;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Mail\Constant\ConfigName was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Valkyrja\Mail\Constant\EnvName;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Mail\Constant\EnvName was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
27
use function array_key_first;
28
29
/**
30
 * Class Config.
31
 *
32
 * @author Melech Mizrachi
33
 */
34
class Config extends ParentConfig
35
{
36
    /**
37
     * @inheritDoc
38
     *
39
     * @var array<string, string>
40
     */
41
    protected static array $envNames = [
42
        ConfigName::DEFAULT_CONFIGURATION         => EnvName::DEFAULT_CONFIGURATION,
43
        ConfigName::CONFIGURATIONS                => EnvName::CONFIGURATIONS,
44
        ConfigName::DEFAULT_MESSAGE_CONFIGURATION => EnvName::DEFAULT_MESSAGE_CONFIGURATION,
45
        ConfigName::MESSAGE_CONFIGURATIONS        => EnvName::MESSAGE_CONFIGURATIONS,
46
    ];
47
48
    public function __construct(
49
        public string $defaultConfiguration = '',
50
        public Configurations|null $configurations = null,
51
        public string $defaultMessageConfiguration = '',
52
        public MessageConfigurations|null $messageConfigurations = null,
53
    ) {
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59
    public function setPropertiesFromEnv(string $env): void
60
    {
61
        if ($this->configurations === null) {
62
            $this->configurations = new Configurations(
63
                mailgun: MailgunConfiguration::fromEnv($env),
64
                phpMailer: PhpMailerConfiguration::fromEnv($env),
65
                log: LogConfiguration::fromEnv($env),
66
                null: NullConfiguration::fromEnv($env)
67
            );
68
        }
69
70
        if ($this->messageConfigurations === null) {
71
            $this->messageConfigurations = new MessageConfigurations(
72
                default: DefaultMessageConfiguration::fromEnv($env)
73
            );
74
        }
75
76
        if ($this->defaultConfiguration === '') {
77
            $this->defaultConfiguration = (string) array_key_first((array) $this->configurations);
78
        }
79
80
        if ($this->defaultMessageConfiguration === '') {
81
            $this->defaultMessageConfiguration = (string) array_key_first((array) $this->messageConfigurations);
82
        }
83
84
        parent::setPropertiesFromEnv($env);
85
    }
86
}
87