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

Multiple   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
ccs 16
cts 16
cp 1
wmc 7
lcom 1
cbo 2

4 Methods

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