-
Notifications
You must be signed in to change notification settings - Fork 15
/
CallbackListDiffer.php
54 lines (46 loc) · 1.08 KB
/
CallbackListDiffer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare( strict_types = 1 );
namespace Diff\Differ;
use Diff\ArrayComparer\StrategicArrayComparer;
use Diff\Comparer\CallbackComparer;
use Diff\DiffOp\DiffOp;
/**
* Differ that only looks at the values of the arrays (and thus ignores key differences).
* Values are compared via callback.
*
* Quantity matters: [42, 42] and [42] are different
*
* @since 0.5
*
* @license BSD-3-Clause
* @author Jeroen De Dauw < [email protected] >
*/
class CallbackListDiffer implements Differ {
/**
* @var ListDiffer
*/
private $differ;
/**
* @since 0.5
*
* @param callable $comparisonCallback
*/
public function __construct( $comparisonCallback ) {
$this->differ = new ListDiffer(
new StrategicArrayComparer( new CallbackComparer( $comparisonCallback ) )
);
}
/**
* @see Differ::doDiff
*
* @since 0.5
*
* @param array $oldValues The first array
* @param array $newValues The second array
*
* @return DiffOp[]
*/
public function doDiff( array $oldValues, array $newValues ): array {
return $this->differ->doDiff( $oldValues, $newValues );
}
}