JsonLimitedResponseHandler   A
last analyzed

Complexity

Total Complexity 2

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 14
cp 0
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 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
use Whoops\Handler\JsonResponseHandler as ParentJsonErrorHandler;
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 JsonLimitedResponseHandler extends ParentJsonErrorHandler
19
{
20
21
    use WhoopsDebugTrait;
22
    use ClassNameBeautifier;
23
24
    /**
25
     * @return int
26
     */
27
    public function handle()
28
    {
29
        $errorData = Formatter::formatExceptionAsDataArray(
30
            $this->getInspector(),
31
            false
32
        );
33
34
        $title = $this->getClassAsTitle($errorData["type"]);
35
36
        $response = array(
37
            'error' => [
38
                "type" => $title,
39
                "message" => $errorData["message"]
40
            ]
41
        );
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