ThrowableHandler::transfer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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 Throwable;
14
15
use function assert;
16
17
use const E_ERROR;
18
19
final class ThrowableHandler implements ThrowableHandlerInterface
20
{
21
    public function __construct(
22
        private ErrorInterface $error,
23
    ) {
24
    }
25
26
    public function handle(Throwable $e, Request $request): ThrowableHandlerInterface
27
    {
28
        $e = $e instanceof Error ? new ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()) : $e;
29
        assert($e instanceof Exception);
30
        $this->error->handle($e, $request);
31
32
        return $this;
33
    }
34
35
    public function transfer(): void
36
    {
37
        $this->error->transfer();
38
    }
39
}
40