CustomCondition   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 49
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCallable() 0 2 1
A isSatisfied() 0 2 1
A getArguments() 0 2 1
1
<?php
2
/**
3
 * @package   WPEmerge
4
 * @author    Atanas Angelov <[email protected]>
5
 * @copyright 2017-2019 Atanas Angelov
6
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GPL-2.0
7
 * @link      https://wpemerge.com/
8
 */
9
10
namespace WPEmerge\Routing\Conditions;
11
12
use WPEmerge\Requests\RequestInterface;
13
14
/**
15
 * Check against a custom callable.
16
 */
17
class CustomCondition implements ConditionInterface {
18
	/**
19
	 * Callable to use
20
	 *
21
	 * @var callable
22
	 */
23
	protected $callable = null;
24
25
	/**
26
	 * Arguments to pass to the callable and controller
27
	 *
28
	 * @var array
29
	 */
30
	protected $arguments = [];
31
32
	/**
33
	 * Constructor
34
	 *
35
	 * @codeCoverageIgnore
36
	 * @param callable $callable
37
	 * @param mixed    ,...$arguments
38
	 */
39
	public function __construct( $callable ) {
40
		$this->callable = $callable;
41
		$this->arguments = array_values( array_slice( func_get_args(), 1 ) );
42
	}
43
44
	/**
45
	 * Get the assigned callable
46
	 *
47
	 * @codeCoverageIgnore
48
	 * @return callable
49
	 */
50
	public function getCallable() {
51
		return $this->callable;
52
	}
53
54
	/**
55
	 * {@inheritDoc}
56
	 */
57 1
	public function isSatisfied( RequestInterface $request ) {
58 1
		return call_user_func_array( $this->callable, $this->arguments );
59
	}
60
61
	/**
62
	 * {@inheritDoc}
63
	 */
64 1
	public function getArguments( RequestInterface $request ) {
65 1
		return $this->arguments;
66
	}
67
}
68