Completed
Push — 1.x ( 55c39d...13cbef )
by Akihito
24s queued 13s
created

ThrowableHandler::transfer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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