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

CallbackComparer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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