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

MultipleCondition   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
ccs 20
cts 20
cp 1
wmc 8
lcom 1
cbo 2

4 Methods

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