Completed
Pull Request — master (#11)
by Tomáš
04:15
created

YamlFileConfigurationBuilder::internalBuild()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3
1
<?php
2
3
/*
4
 * This file is a part of Sculpin.
5
 *
6
 * (c) Dragonfly Development Inc.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Symplify\PHP7_Sculpin\Configuration;
13
14
use Dflydev\DotAccessConfiguration\AbstractConfigurationBuilder;
15
use Dflydev\DotAccessConfiguration\ConfigurationInterface;
16
use Dflydev\DotAccessData\Util as DotAccessDataUtil;
17
use Symfony\Component\Yaml\Yaml;
18
19
final class YamlFileConfigurationBuilder extends AbstractConfigurationBuilder
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private $yamlConfigurationFilenames;
25
26 1
    public function __construct(array $yamlConfigurationFilenames)
27
    {
28 1
        $this->yamlConfigurationFilenames = $yamlConfigurationFilenames;
29 1
    }
30
31
    /**
32
     * {@inheritdoc}.
33
     */
34 1
    public function internalBuild(ConfigurationInterface $configuration)
35
    {
36 1
        $config = [];
37 1
        foreach ($this->yamlConfigurationFilenames as $yamlConfigurationFilename) {
38 1
            if (file_exists($yamlConfigurationFilename)) {
39 1
                $config = DotAccessDataUtil::mergeAssocArray(
40 1
                    $config, Yaml::parse(file_get_contents($yamlConfigurationFilename))
41
                );
42
            }
43
        }
44
45 1
        $configuration->importRaw($config);
46
47 1
        return $configuration;
48
    }
49
}
50