Passed
Push — master ( 0ad36f...731416 )
by Thorsten
01:49
created

YamlConfigLoader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 29
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B load() 0 19 5
1
<?php
2
/**
3
 * This file is part of the daikon-cqrs/config project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace Daikon\Config;
12
13
use Symfony\Component\Yaml\Yaml;
14
15
final class YamlConfigLoader implements ConfigLoaderInterface
16
{
17
    private $yamlParser;
18
19 2
    public function __construct(Yaml $yamlParser = null)
20
    {
21 2
        $this->yamlParser = $yamlParser ?? new Yaml;
22 2
    }
23
24 2
    public function load(array $locations, array $sources): array
25
    {
26 2
        $loadedConfigs = [];
27 2
        foreach ($locations as $location) {
28 2
            if (substr($location, -1) !== '/') {
29 2
                $location .= '/';
30
            }
31 2
            foreach ($sources as $source) {
32 2
                $filepath = $location.$source;
33 2
                if (is_readable($filepath)) {
34 2
                    $loadedConfigs = array_replace_recursive(
35 2
                        $loadedConfigs,
36 2
                        $this->yamlParser->parse(file_get_contents($filepath))
37
                    );
38
                }
39
            }
40
        }
41 2
        return $loadedConfigs;
42
    }
43
}
44