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

CallbackComparer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 24
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A valuesAreEqual() 0 9 2
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