/**
  * @param SiteLinkList $siteLinks
  * @param Diff $patch
  *
  * @return SiteLinkList
  * @throws InvalidArgumentException
  */
 public function getPatchedSiteLinkList(SiteLinkList $siteLinks, Diff $patch)
 {
     $baseData = $this->getSiteLinksInDiffFormat($siteLinks);
     $patchedData = $this->patcher->patch($baseData, $patch);
     $patchedSiteLinks = new SiteLinkList();
     foreach ($patchedData as $siteId => $siteLinkData) {
         if (array_key_exists('name', $siteLinkData)) {
             $patchedSiteLinks->addNewSiteLink($siteId, $siteLinkData['name'], $this->getBadgesFromSiteLinkData($siteLinkData));
         }
     }
     return $patchedSiteLinks;
 }
 /**
  * @param StatementList $statements
  * @param Diff $patch
  *
  * @throws InvalidArgumentException
  * @return StatementList
  */
 public function getPatchedStatementList(StatementList $statements, Diff $patch)
 {
     $statementsByGuid = array();
     /**
      * @var Statement $statement
      */
     foreach ($statements as $statement) {
         $statementsByGuid[$statement->getGuid()] = $statement;
     }
     $patchedList = new StatementList();
     foreach ($this->patcher->patch($statementsByGuid, $patch) as $statement) {
         $patchedList->addStatement($statement);
     }
     return $patchedList;
 }
 private function patchAliases(Fingerprint $fingerprint, Diff $aliasesDiff)
 {
     $patchedAliases = $this->patcher->patch($this->getAliasesArrayForPatching($fingerprint->getAliasGroups()), $aliasesDiff);
     $fingerprint->setAliasGroups($this->getAliasesFromArrayForPatching($patchedAliases));
 }
 /**
  * @param Diff $redirectPatch
  *
  * @return EntityRedirect|null
  */
 private function getPatchedRedirect(Diff $redirectPatch)
 {
     // See getRedirectData() for the structure of the data array.
     $redirData = $this->getRedirectData();
     if (!$redirectPatch->isEmpty()) {
         $patcher = new MapPatcher();
         $redirData = $patcher->patch($redirData, $redirectPatch);
     }
     if (isset($redirData['redirect'])) {
         /* @var EntityHandler $handler */
         $handler = $this->getContentHandler();
         $entityId = $this->getEntityId();
         $targetId = $handler->makeEntityId($redirData['redirect']);
         return new EntityRedirect($entityId, $targetId);
     } else {
         return null;
     }
 }
 public function testErrorOnUnknownDiffOpType()
 {
     $patcher = new MapPatcher();
     $diffOp = $this->getMock('Diff\\DiffOp\\DiffOp');
     $diffOp->expects($this->any())->method('getType')->will($this->returnValue('diff'));
     $diff = new Diff(array($diffOp), true);
     $patcher->patch(array(), $diff);
     $patcher->throwErrors();
     $this->setExpectedException('Diff\\Patcher\\PatcherException');
     $patcher->patch(array(), $diff);
 }