ConfigLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 64
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 10 2
A __construct() 0 8 1
A hydrateConfigs() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\YamlConfig\Business\Loader;
6
7
8
use DataProvider\YamlConfigDataProvider;
9
use DataProvider\YamlConfigFileListDataProvider;
10
use Xervice\YamlConfig\Business\Hydrator\HydratorCollection;
11
use Xervice\YamlConfig\Business\Reader\ReaderInterface;
12
13
class ConfigLoader implements ConfigLoaderInterface
14
{
15
    /**
16
     * @var YamlConfigFileListDataProvider
17
     */
18
    private $fileList;
19
20
    /**
21
     * @var \Xervice\YamlConfig\Business\Reader\ReaderInterface
22
     */
23
    private $fileReader;
24
25
    /**
26
     * @var \Xervice\YamlConfig\Business\Hydrator\HydratorCollection
27
     */
28
    private $hydratorCollection;
29
30
    /**
31
     * ConfigLoader constructor.
32
     *
33
     * @param YamlConfigFileListDataProvider $fileList
34
     * @param \Xervice\YamlConfig\Business\Reader\ReaderInterface $fileReader
35
     * @param \Xervice\YamlConfig\Business\Hydrator\HydratorCollection $hydratorCollection
36
     */
37 2
    public function __construct(
38
        YamlConfigFileListDataProvider $fileList,
39
        ReaderInterface $fileReader,
40
        HydratorCollection $hydratorCollection
41
    ) {
42 2
        $this->fileList = $fileList;
43 2
        $this->fileReader = $fileReader;
44 2
        $this->hydratorCollection = $hydratorCollection;
45 2
    }
46
47
48
    /**
49
     * @return \DataProvider\YamlConfigDataProvider
50
     * @throws \Xervice\YamlConfig\Business\Exception\ConfigException
51
     */
52 2
    public function getConfig(): YamlConfigDataProvider
53
    {
54 2
        $config = new YamlConfigDataProvider();
55
56 2
        foreach ($this->fileList->getFiles() as $file) {
57 2
            $configData = $this->fileReader->getArrayFromFile($file);
58 2
            $config = $this->hydrateConfigs($configData, $config);
59
        }
60
61 2
        return $config;
62
    }
63
64
    /**
65
     * @param $configData
66
     * @param $config
67
     *
68
     * @return \DataProvider\YamlConfigDataProvider
69
     * @throws \Xervice\YamlConfig\Business\Exception\ConfigException
70
     */
71 2
    private function hydrateConfigs($configData, $config): YamlConfigDataProvider
72
    {
73 2
        foreach ($this->hydratorCollection as $hydrator) {
74 1
            $config = $hydrator->hydrateConfig($configData, $config);
75
        }
76 2
        return $config;
77
    }
78
79
}