Completed
Push — master ( c4606f...2cda3d )
by
unknown
15:54 queued 06:31
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 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 24
rs 10
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
 * Operator "CUSTOM" is passed an array of ancestor post ids
9
 */
10
class Post_Ancestor_ID_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 = $environment['post'];
21
		$ancestors = array();
22
23
		if ( $post ) {
24
			$ancestors = array_map( 'intval', get_ancestors( $post_id, $post->post_type ) );
25
		}
26
27
		return $this->compare(
28
			$ancestors,
29
			$this->get_comparison_operator(),
30
			$this->get_value()
31
		);
32
	}
33
}