Completed
Push — development ( bb7ea5...cbb24d )
by
unknown
03:17
created

Post_Ancestor_ID_Condition   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A is_fulfilled() 0 15 2
1
<?php
2
3
namespace Carbon_Fields\Container\Condition;
4
5
/**
6
 * Check if post has a specific ancestor
7
 */
8
class Post_Ancestor_ID_Condition extends Condition {
9
10
	/**
11
	 * Check if the condition is fulfilled
12
	 *
13
	 * @param  array $environment
14
	 * @return bool
15
	 */
16
	public function is_fulfilled( $environment ) {
17
		$post_id = $environment['post_id'];
18
		$post = $environment['post'];
19
		$ancestors = array();
20
21
		if ( $post ) {
22
			$ancestors = array_map( 'intval', get_ancestors( $post_id, $post->post_type ) );
23
		}
24
25
		return $this->compare(
26
			$ancestors,
27
			$this->get_comparison_operator(),
28
			$this->get_value()
29
		);
30
	}
31
}