Passed
Push — php70 ( e501b7...c1737a )
by Jeroen De
06:24 queued 03:40
created

CallbackComparer::valuesAreEqual()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2.032
1
<?php
2
3
namespace Diff\Comparer;
4
5
/**
6
 * Adapter around a comparison callback that implements the ValueComparer
7
 * interface.
8
 *
9
 * @since 0.6
10
 *
11
 * @license GPL-2.0+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class CallbackComparer implements ValueComparer {
15
16
	private $callback;
17
18
	/**
19
	 * @since 0.6
20
	 *
21
	 * @param callable $callback
22
	 */
23 7
	public function __construct( $callback ) {
24 7
		$this->callback = $callback;
25 7
	}
26
27 7
	public function valuesAreEqual( $firstValue, $secondValue ): bool {
28 7
		$valuesAreEqual = call_user_func_array( $this->callback, array( $firstValue, $secondValue ) );
29
30 7
		if ( !is_bool( $valuesAreEqual ) ) {
31
			throw new \RuntimeException( 'ValueComparer callback needs to return a boolean' );
32
		}
33
34 7
		return $valuesAreEqual;
35
	}
36
37
}
38