MultipleCondition   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getConditions() 0 2 1
A isSatisfied() 0 7 3
A getArguments() 0 8 2
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 an array of conditions in an AND logical relationship.
16
 */
17
class MultipleCondition implements ConditionInterface {
18
	/**
19
	 * Array of conditions to check.
20
	 *
21
	 * @var ConditionInterface[]
22
	 */
23
	protected $conditions = [];
24
25
	/**
26
	 * Constructor.
27
	 *
28
	 * @codeCoverageIgnore
29
	 * @param ConditionInterface[] $conditions
30
	 */
31
	public function __construct( $conditions ) {
32
		$this->conditions = $conditions;
33
	}
34
35
	/**
36
	 * Get all assigned conditions
37
	 *
38
	 * @codeCoverageIgnore
39
	 * @return ConditionInterface[]
40
	 */
41
	public function getConditions() {
42
		return $this->conditions;
43
	}
44
45
	/**
46
	 * {@inheritDoc}
47
	 */
48 1
	public function isSatisfied( RequestInterface $request ) {
49 1
		foreach ( $this->conditions as $condition ) {
50 1
			if ( ! $condition->isSatisfied( $request ) ) {
51 1
				return false;
52
			}
53
		}
54 1
		return true;
55
	}
56
57
	/**
58
	 * {@inheritDoc}
59
	 */
60 1
	public function getArguments( RequestInterface $request ) {
61 1
		$arguments = [];
62
63 1
		foreach ( $this->conditions as $condition ) {
64 1
			$arguments = array_merge( $arguments, $condition->getArguments( $request ) );
65
		}
66
67 1
		return $arguments;
68
	}
69
}
70