/**
  * @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 $array
  */
 public function testIndexOf(ReferenceList $array)
 {
     $this->assertFalse($array->indexOf(new Reference()));
     $i = 0;
     foreach ($array as $reference) {
         $this->assertEquals($i++, $array->indexOf($reference));
     }
 }