Skip to content

Commit 9917d17

Browse files
committed
MapDifferInterface
1 parent 92a9a87 commit 9917d17

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Differ/MapDiffer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @license GPL-2.0+
2424
* @author Jeroen De Dauw < [email protected] >
2525
*/
26-
class MapDiffer implements Differ {
26+
class MapDiffer implements Differ, MapDifferInterface {
2727

2828
/**
2929
* @var bool
@@ -40,6 +40,16 @@ class MapDiffer implements Differ {
4040
*/
4141
private $valueComparer;
4242

43+
/**
44+
* Create differ for recursive diffs
45+
*/
46+
public static function createRecursive( ValueComparer $comparer = null, Differ $listDiffer = null ) {
47+
$differ = new self( true, null, $comparer );
48+
$differ->listDiffer = $listDiffer ?? $differ;
49+
50+
return $differ;
51+
}
52+
4353
/**
4454
* The third argument ($comparer) was added in 3.0
4555
*/
@@ -134,7 +144,7 @@ private function getDiffForArrays( array $old, array $new ): Diff {
134144
return new Diff( $this->doDiff( $old, $new ), true );
135145
}
136146

137-
return new Diff( $this->listDiffer->doDiff( $old, $new ), false );
147+
return new Diff( $this->listDiffer->doDiff( $old, $new ), $this->listDiffer instanceof MapDifferInterface );
138148
}
139149

140150
/**

src/Differ/MapDifferInterface.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
declare( strict_types = 1 );
3+
4+
namespace Diff\Differ;
5+
6+
/**
7+
* Interface for differ that can diff two maps.
8+
*
9+
* @since 3.2
10+
*
11+
* @license GPL-2.0+
12+
* @author Alexander Borisov < [email protected] >
13+
*/
14+
interface MapDifferInterface {
15+
16+
}

0 commit comments

Comments
 (0)