Completed
Push — milestone/2_0/container-condit... ( af96ef...c41f81 )
by
unknown
03:01
created

Post_Level_Condition   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A is_fulfilled() 0 11 1
1
<?php
2
3
namespace Carbon_Fields\Container\Condition;
4
5
/**
6
 * Check if a post is on a specific hierarchy level
7
 * 
8
 * Level 1 is considered the root level. Passed values have a forced minimum value of 1.
9
 */
10
class Post_Level_Condition extends Condition {
11
	
12
	/**
13
	 * Check if the condition is fulfilled
14
	 * 
15
	 * @param  array $environment
16
	 * @return bool
17
	 */
18
	public function is_fulfilled( $environment ) {
19
		$post_id = $environment['post_id'];
20
		$post_level = count( get_post_ancestors( $post_id ) ) + 1;
21
		$value = max( 1, intval( $this->get_value() ) );
22
23
		return $this->first_supported_comparer_is_correct(
24
			$post_level,
25
			$this->get_comparison_operator(),
26
			$value
27
		);
28
	}
29
}