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

ExceptionListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onKernelException() 0 5 2
A __construct() 0 3 1
A getSubscribedEvents() 0 4 1
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