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

Config   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 18
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setPropertiesFromEnv() 0 25 5
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\Sms;
15
16
use Valkyrja\Config\Config as ParentConfig;
17
use Valkyrja\Sms\Config\Configurations;
18
use Valkyrja\Sms\Config\DefaultMessageConfiguration;
19
use Valkyrja\Sms\Config\LogConfiguration;
20
use Valkyrja\Sms\Config\MessageConfigurations;
21
use Valkyrja\Sms\Config\NullConfiguration;
22
use Valkyrja\Sms\Config\VonageConfiguration;
23
use Valkyrja\Sms\Constant\ConfigName;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Sms\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...
24
use Valkyrja\Sms\Constant\EnvName;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Sms\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...
25
26
use function array_key_first;
27
28
/**
29
 * Class Config.
30
 *
31
 * @author Melech Mizrachi
32
 */
33
class Config extends ParentConfig
34
{
35
    /**
36
     * @inheritDoc
37
     *
38
     * @var array<string, string>
39
     */
40
    protected static array $envNames = [
41
        ConfigName::DEFAULT_CONFIGURATION         => EnvName::DEFAULT_CONFIGURATION,
42
        ConfigName::CONFIGURATIONS                => EnvName::CONFIGURATIONS,
43
        ConfigName::DEFAULT_MESSAGE_CONFIGURATION => EnvName::DEFAULT_MESSAGE_CONFIGURATION,
44
        ConfigName::MESSAGE_CONFIGURATIONS        => EnvName::MESSAGE_CONFIGURATIONS,
45
    ];
46
47
    public function __construct(
48
        public string $defaultConfiguration = '',
49
        public Configurations|null $configurations = null,
50
        public string $defaultMessageConfiguration = '',
51
        public MessageConfigurations|null $messageConfigurations = null,
52
    ) {
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58
    public function setPropertiesFromEnv(string $env): void
59
    {
60
        if ($this->configurations === null) {
61
            $this->configurations = new Configurations(
62
                vonage: VonageConfiguration::fromEnv($env),
63
                log: LogConfiguration::fromEnv($env),
64
                null: NullConfiguration::fromEnv($env)
65
            );
66
        }
67
68
        if ($this->messageConfigurations === null) {
69
            $this->messageConfigurations = new MessageConfigurations(
70
                default: DefaultMessageConfiguration::fromEnv($env)
71
            );
72
        }
73
74
        if ($this->defaultConfiguration === '') {
75
            $this->defaultConfiguration = (string) array_key_first((array) $this->configurations);
76
        }
77
78
        if ($this->defaultMessageConfiguration === '') {
79
            $this->defaultMessageConfiguration = (string) array_key_first((array) $this->messageConfigurations);
80
        }
81
82
        parent::setPropertiesFromEnv($env);
83
    }
84
}
85