Passed
Push — master ( d2008b...aa9f10 )
by Atanas
01:54
created

MultipleCondition::getArguments()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
ccs 6
cts 6
cp 1
crap 2
1
<?php
2
3
namespace WPEmerge\Routing\Conditions;
4
5
use WPEmerge\Requests\Request;
6
7
/**
8
 * Check against an array of conditions in an AND logical relationship
9
 */
10
class MultipleCondition 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 ConditionFactory::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
		$arguments = [];
49 1
		foreach ( $this->conditions as $condition ) {
50 1
			$arguments = array_merge( $arguments, $condition->getArguments( $request ) );
51 1
		}
52 1
		return $arguments;
53
	}
54
55
	/**
56
	 * Get all assigned conditions
57
	 *
58
	 * @return \WPEmerge\Routing\Conditions\ConditionInterface[]
59
	 */
60 1
	public function getConditions() {
61 1
		return $this->conditions;
62
	}
63
}
64