RoutingListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getSubscribedEvents() 0 6 1
A addPrefix() 0 6 1
1
<?php
2
3
namespace Innmind\RestBundle\EventListener;
4
5
use Innmind\Rest\Server\Events;
6
use Innmind\Rest\Server\Event\RouteEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
class RoutingListener implements EventSubscriberInterface
10
{
11
    protected $prefix;
12
13 4
    public function __construct($prefix)
14
    {
15 4
        $this->prefix = sprintf(
16 4
            '/%s',
17 4
            ltrim(rtrim($prefix, '/'), '/')
18 4
        );
19 4
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 2
    public static function getSubscribedEvents()
25
    {
26
        return [
27 2
            Events::ROUTE => 'addPrefix',
28 2
        ];
29
    }
30
31
    /**
32
     * Add a prefix on each route
33
     *
34
     * @param RouteEvent $event
35
     *
36
     * @return void
37
     */
38 2
    public function addPrefix(RouteEvent $event)
39
    {
40 2
        $route = $event->getRoute();
41
42 2
        $route->setPath($this->prefix . $route->getPath());
43 2
    }
44
}
45