Passed
Push — master ( cc91a3...057c43 )
by Christian
02:20
created

ConfigurationLoader::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Scheb\Tombstone\Analyzer\Config;
4
5
use Symfony\Component\Config\Definition\ConfigurationInterface;
6
use Symfony\Component\Config\Definition\Processor;
7
8
class ConfigurationLoader
9
{
10
    /**
11
     * @var Processor
12
     */
13
    private $processor;
14
15
    /**
16
     * @var ConfigurationInterface
17
     */
18
    private $configuration;
19
20
    public function __construct(Processor $processor, ConfigurationInterface $configuration)
21
    {
22
        $this->processor = $processor;
23
        $this->configuration = $configuration;
24
    }
25
26
    public static function create(): self
27
    {
28
        return new self(new Processor(), new Configuration());
29
    }
30
31
    /**
32
     * @param ConfigProviderInterface[] $configProviders
33
     *
34
     * @return array
35
     */
36
    public function loadConfiguration(array $configProviders): array
37
    {
38
        $rawConfig = [];
39
        foreach ($configProviders as $configProvider) {
40
            $rawConfig = array_replace_recursive($rawConfig, $configProvider->readConfig());
41
        }
42
43
        return $this->processor->processConfiguration($this->configuration, [Configuration::CONFIG_ROOT => $rawConfig]);
44
    }
45
}
46