PlainResponseHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addTraceToOutput() 0 9 2
A handle() 0 15 2
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 PlainResponseHandler extends Handler
18
{
19
20
    use WhoopsDebugTrait;
21
    use WhoopsHeaderTrait;
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::formatExceptionPlain(
48
            $this->getInspector()
49
        );
50
51
        $debug = $this->getDataTable();
52
        if (count($debug) > 0) {
53
            $response .= "\n\n" . json_encode(["debug" => $debug]);
54
        }
55
56
        $this->setProperHeader($this->getException());
57
        echo $response;
58
        return Handler::QUIT;
59
    }
60
}
61