Completed
Push — master ( a4a865...ee8a3d )
by Joao
03:57
created

JsonResponseHandler::isAjaxRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
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
use Whoops\Util\Misc;
13
14
/**
15
 * Catches an exception and converts it to a JSON
16
 * response. Additionally can also return exception
17
 * frames for consumption by an API.
18
 */
19
class JsonResponseHandler extends OriginalJsonHandler
20
{
21
22
    use WhoopsDebugTrait;
23
    use WhoopsHeaderTrait;
24
25
    /**
26
     * @return int
27
     */
28
    public function handle()
29
    {
30
        $response = array(
31
            'error' => Formatter::formatExceptionAsDataArray(
32
                $this->getInspector(),
33
                $this->addTraceToOutput()
0 ignored issues
show
Bug introduced by
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...
34
            ),
35
        );
36
37
        $debug = $this->getDataTable();
38
        if (count($debug) > 0) {
39
            $response["debug"] = $debug;
40
        }
41
42
        echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0);
43
44
        return Handler::QUIT;
45
    }
46
47
}
48