for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Wikibase\DataModel\Services\Diff;
use Diff\Comparer\ComparableComparer;
use Diff\Differ\MapDiffer;
use Diff\DiffOp\Diff\Diff;
use UnexpectedValueException;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Statement\StatementList;
/**
* @since 3.6
*
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < [email protected] >
*/
class StatementListDiffer {
* @since 1.0
* @param StatementList $fromStatements
* @param StatementList $toStatements
* @return Diff
* @throws UnexpectedValueException
public function getDiff( StatementList $fromStatements, StatementList $toStatements ) {
return new Diff(
$this->newDiffer()->doDiff(
$this->toDiffArray( $fromStatements ),
$this->toDiffArray( $toStatements )
),
true
);
}
private function newDiffer(): MapDiffer {
return new MapDiffer( false, null, new ComparableComparer() );
private function toDiffArray( StatementList $statementList ): array {
$statementArray = [];
* @var Statement $statement
foreach ( $statementList as $statement ) {
$guid = $statement->getGuid();
if ( $guid === null ) {
$statementArray[] = $statement;
} else {
$statementArray[$guid] = $statement;
return $statementArray;