Custom_Comparer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A is_correct() 0 12 3
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
}