getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Alchemy\RestBundle\EventListener;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
7
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
8
use Symfony\Component\HttpKernel\KernelEvents;
9
10
class RequestMatchingExceptionListener implements EventSubscriberInterface
11
{
12
13
    /**
14
     * @var ExceptionListener
15
     */
16
    private $exceptionListener;
17
18
    /**
19
     * @var RequestMatcherInterface
20
     */
21
    private $matcher;
22
23
    /**
24
     * @param ExceptionListener $listener
25
     * @param RequestMatcherInterface $matcher
26
     */
27 4
    public function __construct(ExceptionListener $listener, RequestMatcherInterface $matcher)
28
    {
29 4
        $this->exceptionListener = $listener;
30 4
        $this->matcher = $matcher;
31 4
    }
32
33
    /**
34
     * @param GetResponseForExceptionEvent $event
35
     */
36 4
    public function onKernelException(GetResponseForExceptionEvent $event)
37
    {
38 4
        if (! $this->matcher->matches($event->getRequest())) {
39 2
            return;
40
        }
41
42 2
        $this->exceptionListener->onKernelException($event);
43 2
    }
44
45 2
    public static function getSubscribedEvents()
46
    {
47 2
        return array(KernelEvents::EXCEPTION => 'onKernelException');
48
    }
49
}
50