Completed
Push — milestone/2_0/react-ui ( 1c376a...57d10c )
by
unknown
02:51
created

Scalar_Comparer::is_correct()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 23
Code Lines 17

Duplication

Lines 8
Ratio 34.78 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 7
nop 3
dl 8
loc 23
ccs 0
cts 16
cp 0
crap 56
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
namespace Carbon_Fields\Container\Condition\Comparer;
4
5
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
6
7
class Scalar_Comparer extends Comparer {
8
9
	/**
10
	 * Supported comparison signs
11
	 *
12
	 * @var array<string>
13
	 */
14
	protected $supported_comparison_operators = array( '>', '>=', '<', '<=' );
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 ) {
25 View Code Duplication
		if ( ! is_scalar( $a ) ) {
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...
26
			Incorrect_Syntax_Exception::raise( 'Environment value for comparison is not scalar: ' . print_r( $a, true ) );
27
			return false;
28
		}
29
30 View Code Duplication
		if ( ! is_scalar( $b ) ) {
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...
31
			Incorrect_Syntax_Exception::raise( 'Supplied comparison value is not scalar: ' . print_r( $b, true ) );
32
			return false;
33
		}
34
35
		switch ( $comparison_operator ) {
36
			case '>':
37
				return $a > $b;
38
			case '>=':
39
				return $a >= $b;
40
			case '<':
41
				return $a < $b;
42
			case '<=':
43
				return $a <= $b;
44
		}
45
		return false;
46
	}
47
}