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

MultipleCondition   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 52
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConditions() 0 2 1
A __construct() 0 7 2
A isSatisfied() 0 7 3
A getArguments() 0 6 2
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