Completed
Push — master ( 566e39...89d1b0 )
by Jérémy
19s queued 12s
created

ExceptionListener::onKernelException()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 1
b 0
f 0
cc 3
nc 4
nop 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\NewRelicBundle\Listener;
15
16
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface;
17
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
18
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
19
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...sponseForExceptionEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
21
use Symfony\Component\HttpKernel\KernelEvents;
22
23
/**
24
 * Listen to exceptions dispatched by Symfony to log them to NewRelic.
25
 */
26
class ExceptionListener implements EventSubscriberInterface
27
{
28
    private $interactor;
29
30
    public function __construct(NewRelicInteractorInterface $interactor)
31
    {
32
        $this->interactor = $interactor;
33
    }
34
35
    public static function getSubscribedEvents(): array
36
    {
37
        return [
38
            KernelEvents::EXCEPTION => ['onKernelException', 0],
39
        ];
40
    }
41
42
    /**
43
     * @param GetResponseForExceptionEvent|ExceptionEvent $event
44
     */
45
    public function onKernelException(KernelExceptionEvent $event): void
0 ignored issues
show
Bug introduced by
The type Ekino\NewRelicBundle\Listener\KernelExceptionEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
    {
47
        $exception = \method_exists($event, 'getThrowable') ? $event->getThrowable() : $event->getException();
48
        if (!$exception instanceof HttpExceptionInterface) {
49
            $this->interactor->noticeThrowable($exception);
50
        }
51
    }
52
}
53
54
if (\class_exists(ExceptionEvent::class)) {
55
    \class_alias(ExceptionEvent::class, KernelExceptionEvent::class);
56
} else {
57
    \class_alias(GetResponseForExceptionEvent::class, KernelExceptionEvent::class);
58
}
59