Completed
Push — master ( bf3fa9...60ef51 )
by Nikola
02:20
created

FileConfigLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 8 2
A loadFromPath() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Phoundation package.
4
 *
5
 * Copyright (c) Nikola Posa
6
 *
7
 * For full copyright and license information, please refer to the LICENSE file,
8
 * located at the package root folder.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Phoundation\Config\Loader;
14
15
use Phoundation\Config\Config;
16
17
/**
18
 * @author Nikola Posa <[email protected]>
19
 */
20
final class FileConfigLoader extends AbstractLoader
21
{
22
    /**
23
     * @var array
24
     */
25
    private $paths;
26
27
    /**
28
     * @var array
29
     */
30
    private $config = [];
31
32 2
    public function __construct(array $paths)
33
    {
34 2
        $this->paths = $paths;
35 2
    }
36
37 2
    public function __invoke() : Config
38
    {
39 2
        foreach ($this->paths as $path) {
40 2
            $this->loadFromPath($path);
41
        }
42
43 2
        return Config::fromArray($this->config);
44
    }
45
46 2
    private function loadFromPath(string $path)
47
    {
48 2
        $this->config = self::arrayMerge($this->config, include $path);
49 2
    }
50
}
51