Passed
Push — master ( b304d2...1c4610 )
by Indra
01:42
created

ExceptionSubscriber   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 18
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 4 1
A onKernelException() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the MiddlewareBundle
5
 *
6
 * (c) Indra Gunawan <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Indragunawan\MiddlewareBundle\EventSubscriber;
13
14
use Indragunawan\MiddlewareBundle\Exception\SkipControllerException;
15
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
16
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
17
use Symfony\Component\HttpKernel\KernelEvents;
18
19
/**
20
 * @author Indra Gunawan <[email protected]>
21
 */
22
final class ExceptionSubscriber implements EventSubscriberInterface
23
{
24
    public function onKernelException(GetResponseForExceptionEvent $event)
25
    {
26
        $exception = $event->getException();
27
28
        if (!($exception instanceof SkipControllerException)) {
29
            return;
30
        }
31
32
        $event->allowCustomResponseCode();
33
        $event->setResponse($exception->getResponse());
34
    }
35
36
    public static function getSubscribedEvents()
37
    {
38
        return [
39
            KernelEvents::EXCEPTION => ['onKernelException', 255],
40
        ];
41
    }
42
}
43