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

Config::setPropertiesFromEnv()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
cc 3
nc 4
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\Filesystem;
15
16
use Valkyrja\Config\Config as ParentConfig;
17
use Valkyrja\Filesystem\Config\Configurations;
18
use Valkyrja\Filesystem\Config\InMemoryConfiguration;
19
use Valkyrja\Filesystem\Config\LocalFlysystemConfiguration;
20
use Valkyrja\Filesystem\Config\NullConfiguration;
21
use Valkyrja\Filesystem\Config\S3FlysystemConfiguration;
22
use Valkyrja\Filesystem\Constant\ConfigName;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Filesystem\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...
23
use Valkyrja\Filesystem\Constant\EnvName;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Filesystem\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...
24
25
use function array_key_first;
26
27
/**
28
 * Class Config.
29
 *
30
 * @author Melech Mizrachi
31
 */
32
class Config extends ParentConfig
33
{
34
    /**
35
     * @inheritDoc
36
     *
37
     * @var array<string, string>
38
     */
39
    protected static array $envNames = [
40
        ConfigName::DEFAULT_CONFIGURATION => EnvName::DEFAULT_CONFIGURATION,
41
        ConfigName::CONFIGURATIONS        => EnvName::CONFIGURATIONS,
42
    ];
43
44
    public function __construct(
45
        public string $defaultConfiguration = '',
46
        public Configurations|null $configurations = null,
47
    ) {
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53
    public function setPropertiesFromEnv(string $env): void
54
    {
55
        if ($this->configurations === null) {
56
            $this->configurations = new Configurations(
57
                local: LocalFlysystemConfiguration::fromEnv($env),
58
                memory: InMemoryConfiguration::fromEnv($env),
59
                s3: S3FlysystemConfiguration::fromEnv($env),
60
                null: NullConfiguration::fromEnv($env),
61
            );
62
        }
63
64
        if ($this->defaultConfiguration === '') {
65
            $this->defaultConfiguration = (string) array_key_first((array) $this->configurations);
66
        }
67
68
        parent::setPropertiesFromEnv($env);
69
    }
70
}
71