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

Config::setPropertiesBeforeSettingFromEnv()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
rs 10
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\Orm;
15
16
use Valkyrja\Config\Config as ParentConfig;
17
use Valkyrja\Orm\Config\Connections;
18
use Valkyrja\Orm\Config\MysqlConnection;
19
use Valkyrja\Orm\Config\PgsqlConnection;
20
use Valkyrja\Orm\Constant\ConfigName;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Orm\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...
21
use Valkyrja\Orm\Constant\EnvName;
0 ignored issues
show
Bug introduced by
The type Valkyrja\Orm\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...
22
use Valkyrja\Orm\Schema\Contract\Migration;
23
24
/**
25
 * Class Config.
26
 *
27
 * @author Melech Mizrachi
28
 */
29
class Config extends ParentConfig
30
{
31
    /**
32
     * @inheritDoc
33
     *
34
     * @var array<string, string>
35
     */
36
    protected static array $envNames = [
37
        ConfigName::DEFAULT_CONNECTION => EnvName::DEFAULT_CONNECTION,
38
        ConfigName::CONNECTIONS        => EnvName::CONNECTIONS,
39
        ConfigName::MIGRATIONS         => EnvName::MIGRATIONS,
40
    ];
41
42
    /**
43
     * @param array<string, Migration> $migrations A list of migrations
44
     */
45
    public function __construct(
46
        public string $defaultConnection = '',
47
        public Connections|null $connections = null,
48
        public array $migrations = [],
49
    ) {
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function setPropertiesFromEnv(string $env): void
56
    {
57
        if ($this->connections === null) {
58
            $this->connections = new Connections(
59
                mysql: MysqlConnection::fromEnv($env),
60
                pgsql: PgsqlConnection::fromEnv($env)
61
            );
62
        }
63
64
        if ($this->defaultConnection === '') {
65
            $this->defaultConnection = (string) array_key_first((array) $this->connections);
66
        }
67
68
        parent::setPropertiesFromEnv($env);
69
    }
70
}
71