Passed
Push — master ( e3acee...71d19a )
by Jeroen De
02:21
created

CallbackComparer::valuesAreEqual()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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