Test Failed
Pull Request — master (#11)
by Joao
01:49
created

JsonLimitedResponseHandler::handle()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 11
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 21
ccs 0
cts 10
cp 0
crap 6
rs 9.9
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 WhoopsHeaderTrait;
23
    use ClassNameBeautifier;
24
25
    /**
26
     * @return int
27
     */
28
    public function handle()
29
    {
30
        $errorData = Formatter::formatExceptionAsDataArray(
31
            $this->getInspector(),
32
            false
33
        );
34
35
        $title = $this->getClassAsTitle($errorData["type"]);
36
37
        $response = array(
38
            'error' => [
39
                "type" => $title,
40
                "message" => $errorData["message"]
41
            ]
42
        );
43
44
        $this->setProperHeader($this->getException());
45
46
        echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0);
47
48
        return Handler::QUIT;
49
    }
50
}
51