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

YamlConfigLoader::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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