RoutingConfigLoader::load()   A
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 13
nc 7
nop 2
dl 0
loc 22
ccs 0
cts 14
cp 0
crap 42
rs 9.2222
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