ObblmExtraLoader::load()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 8
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 16
ccs 0
cts 9
cp 0
crap 12
rs 10
1
<?php
2
3
namespace Obblm\Core\Routing;
4
5
use Symfony\Component\Config\Loader\Loader;
6
use Symfony\Component\Routing\RouteCollection;
7
8
class ObblmExtraLoader extends Loader
9
{
10
    public const ROUTE_TYPE_NAME = 'obblm';
11
12
    private $isLoaded = false;
13
    private $routeAutoloader = false;
14
15
    public function __construct(RouteAutoloader $routeAutoloader)
16
    {
17
        $this->routeAutoloader = $routeAutoloader;
18
    }
19
20
    public function load($resource, string $type = null)
21
    {
22
        if (true === $this->isLoaded) {
23
            throw new \RuntimeException('Do not add the "extra" loader twice');
24
        }
25
26
        $routes = new RouteCollection();
27
28
        foreach ($this->routeAutoloader->getObblmRoutes() as $route) {
29
            $importedRoutes = $this->import($route['resource'], $route['type']);
30
            $routes->addCollection($importedRoutes);
31
        }
32
33
        $this->isLoaded = true;
34
35
        return $routes;
36
    }
37
38
    public function supports($resource, string $type = null)
39
    {
40
        return 'obblm' === $type;
41
    }
42
}
43