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

Post_Template_Condition   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A is_fulfilled() 11 11 2

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 post has a specific template
7
 * 
8
 * Pass "default" as the value for the default post template
9
 */
10 View Code Duplication
class Post_Template_Condition extends Condition {
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in 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...
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_template = get_post_meta( $post_id, '_wp_page_template', true );
21
		$post_template = $post_template ? $post_template : 'default';
22
23
		return $this->first_supported_comparer_is_correct(
24
			$post_template,
25
			$this->get_comparison_operator(),
26
			$this->get_value()
27
		);
28
	}
29
}