Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Differ/MapDiffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @license GPL-2.0+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class MapDiffer implements Differ {
class MapDiffer implements Differ, MapDifferInterface {

/**
* @var bool
Expand All @@ -40,6 +40,16 @@ class MapDiffer implements Differ {
*/
private $valueComparer;

/**
* Create differ for recursive diffs
*/
public static function createRecursive( ValueComparer $comparer = null, Differ $listDiffer = null ) {
$differ = new self( true, null, $comparer );
$differ->listDiffer = $listDiffer ?? $differ;

return $differ;
}

/**
* The third argument ($comparer) was added in 3.0
*/
Expand Down Expand Up @@ -134,7 +144,7 @@ private function getDiffForArrays( array $old, array $new ): Diff {
return new Diff( $this->doDiff( $old, $new ), true );
}

return new Diff( $this->listDiffer->doDiff( $old, $new ), false );
return new Diff( $this->listDiffer->doDiff( $old, $new ), $this->listDiffer instanceof MapDifferInterface );
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Differ/MapDifferInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare( strict_types = 1 );

namespace Diff\Differ;

/**
* Interface for differ that can diff two maps.
*
* @since 3.2
*
* @license GPL-2.0+
* @author Alexander Borisov < boshurik@gmail.com >
*/
interface MapDifferInterface {

}