Passed
Push — master ( 685651...ff2960 )
by Atanas
02:52
created

CustomCondition::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package   WPEmerge
4
 * @author    Atanas Angelov <[email protected]>
5
 * @copyright 2018 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
	 * {@inheritDoc}
46
	 */
47 1
	public function isSatisfied( RequestInterface $request ) {
48 1
		return call_user_func_array( $this->callable, $this->arguments );
49
	}
50
51
	/**
52
	 * {@inheritDoc}
53
	 */
54 1
	public function getArguments( RequestInterface $request ) {
55 1
		return $this->arguments;
56
	}
57
58
	/**
59
	 * Get the assigned callable
60
	 *
61
	 * @return callable
62
	 */
63 1
	public function getCallable() {
64 1
		return $this->callable;
65
	}
66
}
67