/** * @since 0.4 * * @param ReferenceList $references * @param Summary|null $summary * * @throws ChangeOpException */ protected function removeReference(ReferenceList $references, Summary $summary = null) { if (!$references->hasReferenceHash($this->referenceHash)) { throw new ChangeOpException("Reference with hash {$this->referenceHash} does not exist"); } $references->removeReferenceHash($this->referenceHash); $this->updateSummary($summary, 'remove'); if ($summary !== null) { $summary->addAutoCommentArgs(1); //atomic edit, only one reference changed } }
/** * @since 0.4 * * @param ReferenceList $references * @param Summary|null $summary * * @throws ChangeOpException */ protected function setReference(ReferenceList $references, Summary $summary = null) { if (!$references->hasReferenceHash($this->referenceHash)) { throw new ChangeOpException("Reference with hash {$this->referenceHash} does not exist"); } $currentIndex = $references->indexOf($this->reference); if ($this->index === null && $currentIndex !== false) { // Set index to current index to not have the reference removed and appended but // retain its position within the list of references. $this->index = $currentIndex; } if ($references->hasReference($this->reference) && $this->index === $currentIndex) { throw new ChangeOpException('The statement has already a reference with hash ' . $this->reference->getHash() . ' and index (' . $currentIndex . ') is not changed'); } $references->removeReferenceHash($this->referenceHash); $references->addReference($this->reference, $this->index); $this->updateSummary($summary, 'set'); }
/** * @dataProvider instanceProvider * @param ReferenceList $references */ public function testRemoveReferenceHash(ReferenceList $references) { $references->removeReferenceHash('~=[,,_,,]:3'); $hashes = array(); /** * @var Reference $reference */ foreach ($references as $reference) { $hashes[] = $reference->getHash(); } foreach ($hashes as $hash) { $references->removeReferenceHash($hash); } $this->assertEquals(0, count($references)); }