Passed
Push — master ( 517cb3...2c2725 )
by Atanas
02:15
created

Multiple::isSatisfied()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

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