ErrorListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiistack\Collision;
6
7
use NunoMaduro\Collision\Contracts\Writer;
8
use Symfony\Component\Console\Event\ConsoleErrorEvent;
9
use Symfony\Component\Console\Exception\ExceptionInterface;
10
use Whoops\Exception\Inspector;
11
12
final class ErrorListener
13
{
14
    private Writer $writer;
15
16 1
    public function __construct(Writer $writer)
17
    {
18 1
        $this->writer = $writer;
19
    }
20
21
    /**
22
     * @psalm-suppress InternalMethod
23
     */
24 1
    public function handle(ConsoleErrorEvent $event): void
25
    {
26 1
        $error = $event->getError();
27
28 1
        if (!($error instanceof ExceptionInterface)) {
29 1
            $this->writer
30 1
                ->setOutput($event->getOutput())
31 1
                ->write(new Inspector($error));
32
33 1
            $event->setExitCode(0);
34
        }
35
    }
36
}
37