RouteLoader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 94.12%

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 5
c 6
b 0
f 2
lcom 1
cbo 4
dl 0
loc 65
ccs 32
cts 34
cp 0.9412
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B load() 0 42 3
A supports() 0 4 1
1
<?php
2
3
namespace Innmind\RestBundle;
4
5
use Innmind\Rest\Server\Routing\RouteLoader as ServerRouteLoader;
6
use Innmind\Rest\Server\Routing\RouteKeys;
7
use Symfony\Component\Config\Loader\Loader;
8
use Symfony\Component\Routing\Route;
9
use Symfony\Component\Routing\RouteCollection;
10
11
class RouteLoader extends Loader
12
{
13
    protected $loader;
14
    protected $loaded = false;
15
    protected $routes;
16
17 22
    public function __construct(ServerRouteLoader $loader)
18
    {
19 22
        $this->loader = $loader;
20 22
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 8
    public function load($resource, $type = null)
26
    {
27 8
        if ($this->loaded === true) {
28 2
            throw new \LogicException(
29
                'Do not add the "innmind_rest" loader twice'
30 2
            );
31
        }
32
33 8
        $routes = $this->loader->load($resource, $type);
34
35 8
        foreach ($routes as $route) {
36
            $route
37 8
                ->setDefault(
38 8
                    '_controller',
39 8
                    sprintf(
40 8
                        'innmind_rest.server.controller:%sAction',
41 8
                        $route->getDefault(RouteKeys::ACTION)
42 8
                    )
43 8
                );
44 8
        }
45
46 8
        $serverRoutes = new RouteCollection;
47 8
        $serverRoutes->addCollection($routes);
48
49 8
        $capabilities = new Route('/*');
50 8
        $capabilities
51 8
            ->setMethods('OPTIONS')
52 8
            ->setDefault(
53 8
                '_controller',
54
                'innmind_rest.server.controller:capabilitiesAction'
55 8
            )
56 8
            ->setDefault(
57 8
                RouteKeys::ACTION,
58
                'capabilities'
59 8
            );
60 8
        $serverRoutes->add('innmind_rest_server_capabilities', $capabilities);
61
62 8
        $this->loaded = true;
63 8
        $this->routes = $routes;
64
65 8
        return $serverRoutes;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function supports($resource, $type = null)
72
    {
73
        return $this->loader->supports($resource, $type);
74
    }
75
}
76