JsonResponseHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 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 OriginalJsonHandler;
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 JsonResponseHandler extends OriginalJsonHandler
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()
0 ignored issues
show
Bug introduced by Joao Gilberto Magalhaes
It seems like $this->addTraceToOutput() targeting Whoops\Handler\JsonRespo...ler::addTraceToOutput() can also be of type this<ByJG\RestServer\Whoops\JsonResponseHandler>; however, Whoops\Exception\Formatt...tExceptionAsDataArray() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
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