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

Post_Level_Condition::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
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
}