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

ConfigurationLoader::loadConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 5
cp 0
crap 6
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