Failed Conditions
Branch refactor/route-groups (acb44c)
by Atanas
01:39
created

NegateCondition   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isSatisfied() 0 2 1
A getArguments() 0 2 1
A __construct() 0 5 2
A getUrlWhere() 0 3 2
A setUrlWhere() 0 3 2
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\Facades\RouteCondition;
13
use WPEmerge\Requests\RequestInterface;
14
15
/**
16
 * Negate another condition's result.
17
 *
18
 * @codeCoverageIgnore
19
 */
20
class NegateCondition implements ConditionInterface, HasUrlInterface {
21
	/**
22
	 * Condition to negate.
23
	 *
24
	 * @var ConditionInterface
25
	 */
26
	protected $condition = null;
27
28
	/**
29
	 * Constructor.
30
	 *
31
	 * @param mixed $condition
32
	 */
33
	public function __construct( $condition ) {
34
		if ( $condition instanceof ConditionInterface ) {
35
			$this->condition = $condition;
36
		} else {
37
			$this->condition = call_user_func( [RouteCondition::class, 'make'], func_get_args() );
38
		}
39
	}
40
41
	/**
42
	 * {@inheritDoc}
43
	 */
44
	public function isSatisfied( RequestInterface $request ) {
45
		return ! $this->condition->isSatisfied( $request );
46
	}
47
48
	/**
49
	 * {@inheritDoc}
50
	 */
51
	public function getArguments( RequestInterface $request ) {
52
		return $this->condition->getArguments( $request );
53
	}
54
55
	/**
56
	 * {@inheritDoc}
57
	 * @codeCoverageIgnore
58
	 */
59
	public function getUrlWhere() {
60
		if ( $this->condition instanceof HasUrlInterface ) {
61
			$this->condition->getUrlWhere();
62
		}
63
	}
64
65
	/**
66
	 * {@inheritDoc}
67
	 * @codeCoverageIgnore
68
	 */
69
	public function setUrlWhere( $where ) {
70
		if ( $this->condition instanceof HasUrlInterface ) {
71
			$this->condition->setUrlWhere( $where );
72
		}
73
	}
74
}
75