Skip to content

Commit

Permalink
Factorize into storeCurrentItem
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Dec 19, 2024
1 parent db1f368 commit 5a09b65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public function __construct(Traversable $iterator)
{
$this->iterator = new IteratorIterator($iterator);
$this->iterator->rewind();
if ($this->iterator->valid()) {
$this->storeCurrentItem();
} else {
$this->iterator = null;
}
$this->storeCurrentItem();
}

/** @see https://php.net/countable.count */
Expand Down Expand Up @@ -102,10 +98,6 @@ public function next(): void
$this->iterator->next();
$this->storeCurrentItem();
$this->iteratorAdvanced = true;

if (! $this->iterator->valid()) {
$this->iterator = null;
}
}

next($this->items);
Expand Down Expand Up @@ -155,12 +147,12 @@ private function getIterator(): SPLIterator
*/
private function storeCurrentItem(): void
{
$key = $this->getIterator()->key();
$key = $this->iterator->key();

if ($key === null) {
return;
$this->iterator = null;
} else {
$this->items[$key] = $this->getIterator()->current();
}

$this->items[$key] = $this->getIterator()->current();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function testRewindAfterPartialIteration(): void
iterator_to_array($iterator);
}

public function testRewingAfterToArray(): void
public function testRewindAfterToArray(): void
{
$iterator = new UnrewindableIterator($this->getTraversable([1, 2, 3]));

Expand Down

0 comments on commit 5a09b65

Please sign in to comment.