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

QueryVarCondition::isSatisfied()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace WPEmerge\Routing\Conditions;
4
5
use WPEmerge\Requests\Request;
6
7
/**
8
 * Check against a query var value.
9
 *
10
 * @codeCoverageIgnore
11
 */
12
class QueryVarCondition implements ConditionInterface {
13
	/**
14
	 * Query var name to check against.
15
	 *
16
	 * @var string|null
17
	 */
18
	protected $query_var = null;
19
20
	/**
21
	 * Query var value to check against.
22
	 *
23
	 * @var string
24
	 */
25
	protected $value = '';
26
27
	/**
28
	 * Constructor.
29
	 *
30
	 * @param string $query_var
31
	 * @param string $value
0 ignored issues
show
Documentation introduced by
Should the type for parameter $value not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
32
	 */
33
	public function __construct( $query_var, $value = null ) {
34
		$this->query_var = $query_var;
35
		$this->value = $value;
36
	}
37
38
	/**
39
	 * {@inheritDoc}
40
	 */
41
	public function isSatisfied( Request $request ) {
42
		$query_var_value = get_query_var( $this->query_var, null );
43
44
		if ( $query_var_value === null ) {
45
			return false;
46
		}
47
48
		if ( $this->value === null ) {
49
			return true;
50
		}
51
52
		return strval( $this->value ) === $query_var_value;
53
	}
54
55
	/**
56
	 * {@inheritDoc}
57
	 */
58
	public function getArguments( Request $request ) {
59
		return [$this->query_var, $this->value];
60
	}
61
}
62