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

YamlFileConfigurationBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 31
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A internalBuild() 0 15 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