ErrorListener::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 2
rs 10
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