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

Term_Parent_Condition   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 42.31 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 11
loc 26
rs 10
wmc 6
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B is_fulfilled() 11 23 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}