Completed
Push — master ( 3c91a9...7f2ec8 )
by Jérémy
11s
created

ExceptionListener::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Ekino New Relic bundle.
7
 *
8
 * (c) Ekino - Thomas Rabaix <[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 Ekino\Bundle\NewRelicBundle\Listener;
15
16
use Ekino\Bundle\NewRelicBundle\NewRelic\NewRelicInteractorInterface;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
19
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
20
use Symfony\Component\HttpKernel\KernelEvents;
21
22
/**
23
 * Listen to exceptions dispatched by Symfony to log them to NewRelic.
24
 */
25
class ExceptionListener implements EventSubscriberInterface
26
{
27
    private $interactor;
28
29
    public function __construct(NewRelicInteractorInterface $interactor)
30
    {
31
        $this->interactor = $interactor;
32
    }
33
34
    public static function getSubscribedEvents(): array
35
    {
36
        return [
37
            KernelEvents::EXCEPTION => ['onKernelException', 0],
38
        ];
39
    }
40
41
    public function onKernelException(GetResponseForExceptionEvent $event): void
42
    {
43
        $exception = $event->getException();
44
        if (!$exception instanceof HttpExceptionInterface) {
45
            $this->interactor->noticeThrowable($exception);
46
        }
47
    }
48
}
49