PlainResponseErrorHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 40
ccs 0
cts 13
cp 0
rs 10
c 2
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addTraceToOutput() 0 8 2
A handle() 0 12 1
1
<?php
2
/**
3
 * Whoops - php errors for cool kids
4
 * @author Filipe Dobreira <http://github.com/filp>
5
 */
6
7
namespace ByJG\RestServer\Whoops;
8
9
use Whoops\Exception\Formatter;
10
use Whoops\Handler\Handler;
11
12
/**
13
 * Catches an exception and converts it to a JSON
14
 * response. Additionally can also return exception
15
 * frames for consumption by an API.
16
 */
17
class PlainResponseErrorHandler extends Handler
18
{
19
20
    use WhoopsDebugTrait;
21
    use ClassNameBeautifier;
22
23
    /**
24
     * @var bool
25
     */
26
    private $returnFrames = false;
27
28
    /**
29
     * @param  bool|null $returnFrames
30
     * @return bool|$this
31
     */
32
    public function addTraceToOutput($returnFrames = null)
33
    {
34
        if (func_num_args() == 0) {
35
            return $this->returnFrames;
36
        }
37
38
        $this->returnFrames = (bool)$returnFrames;
39
        return $this;
40
    }
41
42
    /**
43
     * @return int
44
     */
45
    public function handle()
46
    {
47
        $response = Formatter::formatExceptionAsDataArray(
48
            $this->getInspector(),
49
            false
50
        );
51
52
        $title = $this->getClassAsTitle($response["type"]);
53
54
        echo "<html><h1>${title}</h1><p>${response['message']}</p></html>";
55
56
        return Handler::QUIT;
57
    }
58
}
59