Scalar_Comparer::is_correct()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 23

Duplication

Lines 8
Ratio 34.78 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
nc 7
nop 3
dl 8
loc 23
rs 8.6186
c 0
b 0
f 0
ccs 0
cts 16
cp 0
crap 56
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 ) ) {
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 ) ) {
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
}