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

MultipleCondition::setUrlWhere()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 1
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 12
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 an array of conditions in an AND logical relationship.
16
 */
17
class MultipleCondition implements ConditionInterface, HasUrlWhereInterface {
18
	/**
19
	 * Array of conditions to check.
20
	 *
21
	 * @var array<ConditionInterface>
22
	 */
23
	protected $conditions = [];
24
25
	/**
26
	 * Constructor.
27
	 *
28
	 * @codeCoverageIgnore
29
	 * @param array<ConditionInterface> $conditions
30
	 */
31
	public function __construct( $conditions ) {
32
		$this->conditions = $conditions;
33
	}
34
35
	/**
36
	 * {@inheritDoc}
37
	 */
38 1
	public function isSatisfied( RequestInterface $request ) {
39 1
		foreach ( $this->conditions as $condition ) {
40 1
			if ( ! $condition->isSatisfied( $request ) ) {
41 1
				return false;
42
			}
43 1
		}
44 1
		return true;
45
	}
46
47
	/**
48
	 * {@inheritDoc}
49
	 */
50 1
	public function getArguments( RequestInterface $request ) {
51 1
		$arguments = [];
52
53 1
		foreach ( $this->conditions as $condition ) {
54 1
			$arguments = array_merge( $arguments, $condition->getArguments( $request ) );
55 1
		}
56
57 1
		return $arguments;
58
	}
59
60
	/**
61
	 * Get all assigned conditions
62
	 *
63
	 * @codeCoverageIgnore
64
	 * @return \WPEmerge\Routing\Conditions\ConditionInterface[]
65
	 */
66
	public function getConditions() {
67
		return $this->conditions;
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 * @codeCoverageIgnore
73
	 */
74
	public function getUrlWhere() {
75
		return [];
76
	}
77
78
	/**
79
	 * {@inheritDoc}
80
	 * @codeCoverageIgnore
81
	 */
82
	public function setUrlWhere( $where ) {
83
		foreach ( $this->conditions as $condition ) {
84
			if ( $condition instanceof HasUrlWhereInterface ) {
85
				$condition->setUrlWhere( $where );
86
			}
87
		}
88
	}
89
}
90