JsonResponseErrorHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 28
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 3
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
use Whoops\Handler\JsonResponseHandler as OriginalJsonErrorHandler;
12
13
/**
14
 * Catches an exception and converts it to a JSON
15
 * response. Additionally can also return exception
16
 * frames for consumption by an API.
17
 */
18
class JsonResponseErrorHandler extends OriginalJsonErrorHandler
19
{
20
21
    use WhoopsDebugTrait;
22
    use WhoopsHeaderTrait;
23
24
    /**
25
     * @return int
26
     */
27
    public function handle()
28
    {
29
        $response = array(
30
            'error' => Formatter::formatExceptionAsDataArray(
31
                $this->getInspector(),
32
                $this->addTraceToOutput()
33
            ),
34
        );
35
36
        $debug = $this->getDataTable();
37
        if (count($debug) > 0) {
38
            $response["debug"] = $debug;
39
        }
40
41
        $this->setProperHeader($this->getException());
42
43
        echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0);
44
45
        return Handler::QUIT;
46
    }
47
}
48