Conditions | 4 |
Paths | 5 |
Total Lines | 23 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
34 | public function handle() { |
||
35 | |||
36 | if ( ! $this->isRestRequest() ) { |
||
37 | return Handler::DONE; |
||
38 | } |
||
39 | |||
40 | $data = Formatter::formatExceptionAsDataArray( $this->getInspector(), $this->addTraceToOutput() ); |
||
41 | $response = array( |
||
42 | 'code' => $data['type'], |
||
43 | 'message' => $data['message'], |
||
44 | 'data' => $data, |
||
45 | ); |
||
46 | |||
47 | if ( Misc::canSendHeaders() ) { |
||
48 | status_header( 500 ); |
||
49 | header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); |
||
50 | } |
||
51 | |||
52 | $json_options = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? JSON_PRETTY_PRINT : 0; |
||
53 | |||
54 | echo wp_json_encode( $response, $json_options ); |
||
55 | |||
56 | return Handler::QUIT; |
||
57 | } |
||
59 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: