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

Any_Contain_Comparer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 32
loc 32
rs 10
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A is_correct() 14 14 4

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\Comparer;
4
5
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
6
7 View Code Duplication
class Any_Contain_Comparer extends Comparer {
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...
8
9
	/**
10
	 * Supported comparison signs
11
	 *
12
	 * @var array<string>
13
	 */
14
	protected $supported_comparison_operators = array( 'IN', 'NOT IN' );
1 ignored issue
show
Comprehensibility Naming introduced by
The variable name $supported_comparison_operators exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
15
16
	/**
17
	 * Check if comparison is true for $a and $b
18
	 *
19
	 * @param mixed  $a
20
	 * @param string $comparison_operator
21
	 * @param mixed  $b
22
	 * @return bool
23
	 */
24
	public function is_correct( $a, $comparison_operator, $b ) {
2 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $a. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $b. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
25
		if ( ! is_array( $b ) ) {
26
			Incorrect_Syntax_Exception::raise( 'Supplied comparison value is not an array: ' . print_r( $b, true ) );
27
			return false;
28
		}
29
30
		switch ( $comparison_operator ) {
31
			case 'IN':
32
				return ! empty( array_intersect( $a, $b ) );
33
			case 'NOT IN':
34
				return empty( array_intersect( $a, $b ) );
35
		}
36
		return false;
37
	}
38
}