ThrowableListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
dl 0
loc 26
c 2
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleEvent() 0 13 3
A __construct() 0 3 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