Completed
Push — master ( c4606f...2cda3d )
by
unknown
15:54 queued 06:31
created

Term_Parent_Condition::is_fulfilled()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 23
Code Lines 17

Duplication

Lines 11
Ratio 47.83 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 6
eloc 17
c 1
b 0
f 1
nc 10
nop 1
dl 11
loc 23
rs 8.5906
1
<?php
2
3
namespace Carbon_Fields\Container\Condition;
4
5
/**
6
 * Check if term has a specific parent
7
 *
8
 * Accepts the following values:
9
 *     Operators "=" and "!=":
10
 *         array(
11
 *             'value'=>...,
12
 *             'taxonomy'=>...,
13
 *             ['field'=>...] // "slug", "term_id" etc. - see get_term_by()
14
 *         )
15
 *
16
 *     Operators "IN" and "NOT IN":
17
 *         array(
18
 *             array(
19
 *                 'value'=>...,
20
 *                 'taxonomy'=>...,
21
 *                 ['field'=>...]
22
 *             ),
23
 *             ...
24
 *         )
25
 *
26
 *     Operator "CUSTOM" is passed the parent term_id
27
 */
28
class Term_Parent_Condition extends Term_Condition {
29
30
	public function is_fulfilled( $environment ) {
31
		$term = $environment['term'];
32
		$parent_term_id = $term ? intval( $term->parent ) : 0;
33
34
		$value = $this->get_value();
35 View Code Duplication
		switch ( $this->get_comparison_operator() ) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
			case '=': // fallthrough intended
37
			case '!=':
38
				$value = $this->get_term_id_from_full_term_descriptor( $value );
39
				break;
40
41
			case 'IN': // fallthrough intended
42
			case 'NOT IN':
43
				$value = $this->get_term_ids_from_full_term_descriptors( $value );
44
				break;
45
		}
46
47
		return $this->compare(
48
			$parent_term_id,
49
			$this->get_comparison_operator(),
50
			$value
51
		);
52
	}
53
}