/** * @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 testHasReferenceHash(ReferenceList $references) { $this->assertFalse($references->hasReferenceHash('~=[,,_,,]:3')); /** * @var Hashable $reference */ foreach ($references as $reference) { $this->assertTrue($references->hasReferenceHash($reference->getHash())); } }