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

ExceptionSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
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