Passed
Pull Request — master (#39)
by
unknown
04:19 queued 01:47
created

ConfigFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 28
ccs 15
cts 15
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 23 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Runner;
6
7
use ErrorException;
8
use Yiisoft\Config\Config;
9
use Yiisoft\Config\ConfigPaths;
10
use Yiisoft\Config\Modifier\RecursiveMerge;
11
use Yiisoft\Config\Modifier\ReverseMerge;
12
13
/**
14
 * Creates a Config instance for a given environment.
15
 */
16
final class ConfigFactory
17
{
18
    /**
19
     * @throws ErrorException If the environment does not exist.
20
     */
21 11
    public static function create(
22
        ConfigPaths $paths,
23
        ?string $environment,
24
        ?string $configGroupPostfix = null,
25
    ): Config {
26 11
        $paramsGroups = ['params'];
27 11
        if ($configGroupPostfix !== null) {
28 9
            $paramsGroups[] = 'params-' . $configGroupPostfix;
29
        }
30
31 11
        $eventGroups = ['events'];
32 11
        if ($configGroupPostfix !== null) {
33 9
            $eventGroups[] = 'events-' . $configGroupPostfix;
34
        }
35
36 11
        return new Config(
37 11
            $paths,
38 11
            $environment,
39 11
            [
40 11
                ReverseMerge::groups(...$eventGroups),
41 11
                RecursiveMerge::groups(...$paramsGroups, ...$eventGroups),
42 11
            ],
43 11
            'params',
44 11
        );
45
    }
46
}
47