ErrorHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 7 1
A transfer() 0 4 1
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
    /** @var ?ResourceObject */
21
    private $errorPage;
22
23
    /** @var TransferInterface */
24
    private $responder;
25
26
    /** @var ErrorLogger */
27
    private $logger;
28
29
    /** @var ErrorPageFactoryInterface */
30
    private $factory;
31
32
    public function __construct(TransferInterface $responder, ErrorLogger $logger, ErrorPageFactoryInterface $factory)
33
    {
34
        $this->responder = $responder;
35
        $this->logger = $logger;
36
        $this->factory = $factory;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function handle(Exception $e, Request $request) // phpcs:ignore SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException
43
    {
44
        $this->logger->__invoke($e, $request);
45
        $this->errorPage = $this->factory->newInstance($e, $request);
46
47
        return $this;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function transfer(): void
54
    {
55
        $this->responder->__invoke($this->errorPage ?? new NullPage(), []);
56
    }
57
}
58