-
Notifications
You must be signed in to change notification settings - Fork 15
/
OrderedListDiffer.php
53 lines (45 loc) · 1.1 KB
/
OrderedListDiffer.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
<?php
declare( strict_types = 1 );
namespace Diff\Differ;
use Diff\ArrayComparer\OrderedArrayComparer;
use Diff\Comparer\ValueComparer;
use Diff\DiffOp\DiffOp;
/**
* Differ that looks at the order of the values and the values of the arrays.
*
* Quantity matters: [42, 42] and [42] are different
* Order matters: [42, 43] and [43, 42] are different
*
* @since 0.9
*
* @license BSD-3-Clause
* @author Jeroen De Dauw < [email protected] >
* @author Tobias Gritschacher < [email protected] >
*/
class OrderedListDiffer implements Differ {
/**
* @var ListDiffer
*/
private $differ;
/**
* @since 0.9
*
* @param ValueComparer $comparer
*/
public function __construct( ValueComparer $comparer ) {
$this->differ = new ListDiffer( new OrderedArrayComparer( $comparer ) );
}
/**
* @see Differ::doDiff
*
* @since 0.9
*
* @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 );
}
}