RoutingConfigLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/boot project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Boot\Config;
10
11
use Aura\Router\RouterContainer;
12
use Daikon\Config\ConfigLoaderInterface;
13
use Daikon\Config\ConfigProviderInterface;
14
15
final class RoutingConfigLoader implements ConfigLoaderInterface
16
{
17
    private RouterContainer $router;
18
19
    private ConfigProviderInterface $configProvider;
20
21
    public function __construct(RouterContainer $router, ConfigProviderInterface $configProvider)
22
    {
23
        $this->router = $router;
24
        $this->configProvider = $configProvider;
25
    }
26
27
    public function load(array $locations, array $sources): array
28
    {
29
        $router = $this->router;
30
        //these variables are in scope for included routing files
31
        $map = $router->getMap();
0 ignored issues
show
Unused Code introduced by
The assignment to $map is dead and can be removed.
Loading history...
32
        $configProvider = $this->configProvider;
0 ignored issues
show
Unused Code introduced by
The assignment to $configProvider is dead and can be removed.
Loading history...
33
34
        $loadedConfigs = [];
35
        foreach ($locations as $location) {
36
            if (substr($location, -1) !== '/') {
37
                $location .= '/';
38
            }
39
            foreach ($sources as $source) {
40
                $filepath = $location.$source;
41
                if (is_file($filepath) && is_readable($filepath)) {
42
                    require_once $filepath;
43
                    $loadedConfigs[] = $filepath;
44
                }
45
            }
46
        }
47
48
        return $loadedConfigs;
49
    }
50
}
51