Custom_Comparer::is_correct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 3
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
ccs 0
cts 7
cp 0
crap 12
1
<?php
2
3
namespace Carbon_Fields\Container\Condition\Comparer;
4
5
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
6
7
class Custom_Comparer extends Comparer {
8
9
	/**
10
	 * Supported comparison signs
11
	 *
12
	 * @var array<string>
13
	 */
14
	protected $supported_comparison_operators = array( 'CUSTOM' );
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
		if ( ! is_callable( $b ) ) {
26
			Incorrect_Syntax_Exception::raise( 'Supplied comparison value is not a callable: ' . print_r( $b, true ) );
27
			return false;
28
		}
29
30
		switch ( $comparison_operator ) {
31
			case 'CUSTOM':
32
				return (bool) $b( $a );
33
		}
34
		return false;
35
	}
36
}