ExceptionSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

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