Passed
Push — master ( db8d74...f13993 )
by Atanas
01:54
created

Handler::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 6
cts 6
cp 1
crap 2
1
<?php
2
3
namespace WPEmerge\Routing;
4
5
use WPEmerge\Helpers\Handler as GenericHandler;
6
7
/**
8
 * Represent a Closure or a controller method to be executed in response to a request
9
 */
10
class Handler {
11
	/**
12
	 * Actual handler
13
	 *
14
	 * @var GenericHandler
15
	 */
16
	protected $handler = null;
17
18
	/**
19
	 * Constructor
20
	 *
21
	 * @param string|\Closure $handler
22
	 */
23 1
	public function __construct( $handler ) {
24 1
		$this->handler = new GenericHandler( $handler );
25 1
	}
26
27
	/**
28
	 * Get the handler
29
	 *
30
	 * @return GenericHandler
31
	 */
32 1
	public function get() {
33 1
		return $this->handler;
34
	}
35
36
	/**
37
	 * Execute the handler
38
	 *
39
	 * @param  mixed $arguments,...
0 ignored issues
show
Bug introduced by
There is no parameter named $arguments,.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40
	 * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use object|integer|double|null|boolean.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
41
	 */
42 3
	public function execute() {
43 3
		$arguments = func_get_args();
44 3
		$response = call_user_func_array( [$this->handler, 'execute'], $arguments );
45
46 3
		if ( is_string( $response ) ) {
47 1
			return wpm_output( $response );
48
		}
49
50 2
		if ( is_array( $response ) ) {
51 1
			return wpm_json( $response );
52
		}
53
54 1
		return $response;
55
	}
56
}
57