Completed
Push — develop ( 186fbd...dd6a23 )
by Baptiste
02:23
created

ExceptionListener::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\EventListener;
5
6
use Innmind\Http\Exception\Http\ExceptionInterface;
7
use Symfony\Component\{
8
    EventDispatcher\EventSubscriberInterface,
9
    HttpKernel\KernelEvents,
10
    HttpKernel\Event\GetResponseForExceptionEvent,
11
    HttpKernel\Exception\HttpException
12
};
13
14
final class ExceptionListener implements EventSubscriberInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 1
    public static function getSubscribedEvents()
20
    {
21
        return [
22 1
            KernelEvents::EXCEPTION => [['transformException', 100]],
23
        ];
24
    }
25
26
    /**
27
     * Transform an innmind http exception into a symfony one to generate the
28
     * appropriate http response
29
     *
30
     * @param GetResponseForExceptionEvent $event
31
     *
32
     * @return void
33
     */
34 2
    public function transformException(GetResponseForExceptionEvent $event)
35
    {
36 2
        $exception = $event->getException();
37
38 2
        if (!$exception instanceof ExceptionInterface) {
39 1
            return;
40
        }
41
42 1
        $event->setException(
43 1
            new HttpException(
44 1
                $exception->httpCode(),
45 1
                null,
46
                $exception
47
            )
48
        );
49 1
    }
50
}
51