ErrorHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Provide\Error;
6
7
use BEAR\Resource\ResourceObject;
8
use BEAR\Sunday\Extension\Error\ErrorInterface;
9
use BEAR\Sunday\Extension\Router\RouterMatch as Request;
10
use BEAR\Sunday\Extension\Transfer\TransferInterface;
11
use Exception;
12
13
/**
14
 * vnd.error for BEAR.Package
15
 *
16
 * @see https://github.com/blongden/vnd.error
17
 */
18
final class ErrorHandler implements ErrorInterface
19
{
20
    private ResourceObject|null $errorPage = null;
21
22
    public function __construct(
23
        private TransferInterface $responder,
24
        private ErrorLogger $logger,
25
        private ErrorPageFactoryInterface $factory,
26
    ) {
27
    }
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    public function handle(Exception $e, Request $request) // phpcs:ignore SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException
33
    {
34
        ($this->logger)($e, $request);
35
        $this->errorPage = $this->factory->newInstance($e, $request);
36
37
        return $this;
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function transfer(): void
44
    {
45
        ($this->responder)($this->errorPage ?? new NullPage(), []);
46
    }
47
}
48