IgnitionWhoopsHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 20 2
A setException() 0 4 1
1
<?php
2
3
namespace Facade\Ignition\ErrorPage;
4
5
use Error;
6
use ErrorException;
7
use Whoops\Handler\Handler;
8
9
class IgnitionWhoopsHandler extends Handler
10
{
11
    /** @var \Facade\Ignition\ErrorPage\ErrorPageHandler */
12
    protected $errorPageHandler;
13
14
    /** @var \Throwable */
15
    protected $exception;
16
17
    public function __construct(ErrorPageHandler $errorPageHandler)
18
    {
19
        $this->errorPageHandler = $errorPageHandler;
20
    }
21
22
    public function handle(): ?int
23
    {
24
        try {
25
            $this->errorPageHandler->handle($this->exception);
26
        } catch (Error $error) {
27
            // Errors aren't caught by Whoops.
28
            // Convert the error to an exception and throw again.
29
30
            throw new ErrorException(
31
                $error->getMessage(),
32
                $error->getCode(),
33
                1,
34
                $error->getFile(),
35
                $error->getLine(),
36
                $error
37
            );
38
        }
39
40
        return Handler::QUIT;
41
    }
42
43
    /** @param \Throwable $exception */
44
    public function setException($exception): void
45
    {
46
        $this->exception = $exception;
47
    }
48
}
49