Passed
Pull Request — master (#11)
by Joao
01:43
created

JsonLimitedResponseHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 31
ccs 0
cts 9
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 21 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 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