Passed
Push — master ( b7467b...db04eb )
by Atanas
02:41
created

PostSlug   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 32
ccs 0
cts 8
cp 0
rs 10
wmc 4
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A satisfied() 0 4 2
A getArguments() 0 3 1
1
<?php
2
3
namespace Obsidian\Routing\Conditions;
4
5
use Obsidian\Request;
6
7
/**
8
 * Check against the current post's slug
9
 */
10
class PostSlug implements ConditionInterface {
11
	/**
12
	 * Post slug to check against
13
	 *
14
	 * @var string
15
	 */
16
	protected $post_slug = '';
17
18
	/**
19
	 * Constructor
20
	 *
21
	 * @param string $post_slug
22
	 */
23
	public function __construct( $post_slug ) {
24
		$this->post_slug = $post_slug;
25
	}
26
27
	/**
28
	 * {@inheritDoc}
29
	 */
30
	public function satisfied( Request $request ) {
31
		$post = get_post();
32
		return ( $post && $this->post_slug === $post->post_name );
33
	}
34
35
	/**
36
	 * {@inheritDoc}
37
	 */
38
	public function getArguments( Request $request ) {
39
		return [$this->post_slug];
40
	}
41
}
42