Admin_Ajax_Handler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isAjaxRequest() 0 4 2
A handle() 0 19 3
1
<?php
2
namespace Rarst\wps;
3
4
use Whoops\Exception\Formatter;
5
use Whoops\Handler\Handler;
6
use Whoops\Handler\JsonResponseHandler;
7
use Whoops\Util\Misc;
8
9
/**
10
 * WordPress-specific version of Json handler.
11
 */
12
class Admin_Ajax_Handler extends JsonResponseHandler {
13
14
	/**
15
	 * @return bool
16
	 */
17
	private function isAjaxRequest() {
18
19
		return defined( 'DOING_AJAX' ) && DOING_AJAX;
20
	}
21
22
	/**
23
	 * @return int
24
	 */
25
	public function handle() {
26
27
		if ( ! $this->isAjaxRequest() ) {
28
			return Handler::DONE;
29
		}
30
31
		$response = array(
32
			'success' => false,
33
			'data'    => Formatter::formatExceptionAsDataArray( $this->getInspector(), $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<Rarst\wps\Admin_Ajax_Handler>; 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
		if ( Misc::canSendHeaders() ) {
37
			header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
38
		}
39
40
		echo wp_json_encode( $response, JSON_PRETTY_PRINT );
41
42
		return Handler::QUIT;
43
	}
44
}
45