Completed
Push — master ( c2e0fc...bf3fa9 )
by Nikola
02:00
created

FileLoader::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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