ThrowableListener::handleEvent()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 13
c 1
b 0
f 0
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Gvera\Listeners;
4
5
use Gvera\Events\Event;
6
use Gvera\Exceptions\GvException;
7
use Monolog\Logger;
8
9
class ThrowableListener implements EventListenerInterface
10
{
11
    public $logger;
12
13
    public function __construct(Logger $logger)
14
    {
15
        $this->logger = $logger;
16
    }
17
18
    /**
19
     * @param Event $event
20
     * @return void
21
     */
22
    public function handleEvent(Event $event): void
23
    {
24
        $throwable = $event->getThrowable();
0 ignored issues
show
Bug introduced by
The method getThrowable() does not exist on Gvera\Events\Event. It seems like you code against a sub-type of Gvera\Events\Event such as Gvera\Events\ThrowableFiredEvent. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        /** @scrutinizer ignore-call */ 
25
        $throwable = $event->getThrowable();
Loading history...
25
        $httpResponse = $event->getHttpResponse();
0 ignored issues
show
Bug introduced by
The method getHttpResponse() does not exist on Gvera\Events\Event. It seems like you code against a sub-type of Gvera\Events\Event such as Gvera\Events\ThrowableFiredEvent. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        /** @scrutinizer ignore-call */ 
26
        $httpResponse = $event->getHttpResponse();
Loading history...
26
        if ($event->isDevMode()) {
0 ignored issues
show
Bug introduced by
The method isDevMode() does not exist on Gvera\Events\Event. It seems like you code against a sub-type of Gvera\Events\Event such as Gvera\Events\ThrowableFiredEvent. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        if ($event->/** @scrutinizer ignore-call */ isDevMode()) {
Loading history...
27
            $httpResponse->terminate($event->getThrowable()->getMessage());
28
            return;
29
        }
30
31
        $arguments = is_a($throwable, GvException::class) ? $throwable->getArguments() : [];
32
        $this->logger->err($throwable->getMessage(), $arguments);
33
34
        $httpResponse->redirect('/');
35
    }
36
}
37