Completed
Push — master ( da5ca0...e55bc1 )
by Atanas
02:05
created

MultipleCondition::isSatisfied()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WPEmerge\Routing\Conditions;
4
5
use WPEmerge\Facades\RouteCondition;
6
use WPEmerge\Requests\Request;
7
8
/**
9
 * Check against an array of conditions in an AND logical relationship
10
 */
11
class MultipleCondition implements ConditionInterface {
12
	/**
13
	 * Array of conditions to check
14
	 *
15
	 * @var array<ConditionInterface>
16
	 */
17
	protected $conditions = [];
18
19
	/**
20
	 * Constructor
21
	 *
22
	 * @param array $conditions
23
	 */
24
	public function __construct( $conditions ) {
25 1
		$this->conditions = array_map( function ( $condition ) {
26 1
			if ( $condition instanceof ConditionInterface ) {
27 1
				return $condition;
28
			}
29 1
			return RouteCondition::make( $condition );
30 1
		}, $conditions );
31 1
	}
32
33
	/**
34
	 * {@inheritDoc}
35
	 */
36 1
	public function isSatisfied( Request $request ) {
37 1
		foreach ( $this->conditions as $condition ) {
38 1
			if ( ! $condition->isSatisfied( $request ) ) {
39 1
				return false;
40
			}
41 1
		}
42 1
		return true;
43
	}
44
45
	/**
46
	 * {@inheritDoc}
47
	 */
48 1
	public function getArguments( Request $request ) {
49 1
		$arguments = [];
50 1
		foreach ( $this->conditions as $condition ) {
51 1
			$arguments = array_merge( $arguments, $condition->getArguments( $request ) );
52 1
		}
53 1
		return $arguments;
54
	}
55
56
	/**
57
	 * Get all assigned conditions
58
	 *
59
	 * @return \WPEmerge\Routing\Conditions\ConditionInterface[]
60
	 */
61 1
	public function getConditions() {
62 1
		return $this->conditions;
63
	}
64
}
65