Skip to content

Commit

Permalink
Merge pull request #93 from MaxGoryunov/feature/85
Browse files Browse the repository at this point in the history
Feature/85
  • Loading branch information
MaxGoryunov committed Aug 27, 2021
2 parents 09f66c5 + d87d879 commit e96d259
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/SavingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,28 @@ public function __construct(
}

/**
* {@inheritDoc}
* @return TValue|false
* Returns target after adding a value from origin.
*
* @phpstan-return AddingIterator<TKey, TValue>
* @return AddingIterator
*/
public function current(): mixed
private function added(): AddingIterator
{
/**
* @todo #66:25min Codebeat complains about similar code in two methods.
* It should be refactored.
* @todo #85:40min There is a private function in this class. It should
* be removed without creating the code duplication problem again.
*/
$this->target = $this->target->from($this->origin);
return $this->target->current();
return $this->target;
}

/**
* {@inheritDoc}
* @return TValue|false
*/
public function current(): mixed
{
return $this->added()->current();
}

/**
Expand All @@ -60,8 +71,7 @@ public function current(): mixed
*/
public function key(): mixed
{
$this->target = $this->target->from($this->origin);
return $this->target->key();
return $this->added()->key();
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/src/SavingIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SavingIteratorTest extends TestCase

/**
* @covers ::__construct
* @covers ::added
* @covers ::rewind
* @covers ::valid
* @covers ::current
Expand Down Expand Up @@ -101,6 +102,7 @@ public function testDoesNotCallOriginIfValuesAreInCache(): void

/**
* @covers ::__construct
* @covers ::added
* @covers ::rewind
* @covers ::valid
* @covers ::current
Expand Down Expand Up @@ -138,6 +140,7 @@ public function testWorksWithGenerator(): void

/**
* @covers ::__construct
* @covers ::added
* @covers ::rewind
* @covers ::valid
* @covers ::current
Expand Down Expand Up @@ -173,6 +176,7 @@ public function testWorksWithGeneratorMultipleTimes(): void

/**
* @covers ::__construct
* @covers ::added
* @covers ::rewind
* @covers ::valid
* @covers ::current
Expand Down Expand Up @@ -204,6 +208,7 @@ public function testWorksWithEmptyGenerator(): void

/**
* @covers ::__construct
* @covers ::added
* @covers ::rewind
* @covers ::valid
* @covers ::current
Expand Down Expand Up @@ -234,6 +239,7 @@ public function testIterationsGiveSameResults(): void

/**
* @covers ::__construct
* @covers ::added
* @covers ::rewind
* @covers ::valid
* @covers ::current
Expand Down Expand Up @@ -275,6 +281,7 @@ function (Iterator $iterator) use ($input): void {

/**
* @covers ::__construct
* @covers ::added
* @covers ::rewind
* @covers ::valid
* @covers ::current
Expand Down Expand Up @@ -302,6 +309,7 @@ public function testWorksWithEmptyIterator(): void

/**
* @covers ::__construct
* @covers ::added
* @covers ::rewind
* @covers ::valid
* @covers ::current
Expand Down

0 comments on commit e96d259

Please sign in to comment.