ThrowableHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 11 2
A transfer() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Sunday\Provide\Error;
6
7
use BEAR\Sunday\Extension\Error\ErrorInterface;
8
use BEAR\Sunday\Extension\Error\ThrowableHandlerInterface;
9
use BEAR\Sunday\Extension\Router\RouterMatch as Request;
10
use Error;
11
use ErrorException;
12
use Exception;
13
use Override;
14
use Throwable;
15
16
use const E_ERROR;
17
18
final class ThrowableHandler implements ThrowableHandlerInterface
19
{
20
    public function __construct(
21
        private ErrorInterface $error,
22
    ) {
23
    }
24
25
    #[Override]
26
    public function handle(Throwable $e, Request $request): ThrowableHandlerInterface
27
    {
28
        if ($e instanceof Error) {
29
            $e = new ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine(), $e);
0 ignored issues
show
Bug introduced by
$e of type Error is incompatible with the type Exception expected by parameter $previous of ErrorException::__construct(). ( Ignorable by Annotation )

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

29
            $e = new ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine(), /** @scrutinizer ignore-type */ $e);
Loading history...
30
        }
31
32
        /** @var Exception $e */
33
        $this->error->handle($e, $request);
34
35
        return $this;
36
    }
37
38
    #[Override]
39
    public function transfer(): void
40
    {
41
        $this->error->transfer();
42
    }
43
}
44