ArrayIteratorFixture.php 809 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace MathPHP\Tests\Util;
  3. class ArrayIteratorFixture implements \Iterator
  4. {
  5. /** @var array */
  6. private $values;
  7. /** @var int */
  8. private $i;
  9. public function __construct(array $values)
  10. {
  11. $this->values = $values;
  12. $this->i = 0;
  13. }
  14. public function rewind(): void
  15. {
  16. $this->i = 0;
  17. }
  18. /**
  19. * @return mixed
  20. */
  21. #[\ReturnTypeWillChange]
  22. public function current()
  23. {
  24. return $this->values[$this->i];
  25. }
  26. /**
  27. * @return int
  28. */
  29. public function key(): int
  30. {
  31. return $this->i;
  32. }
  33. public function next(): void
  34. {
  35. ++$this->i;
  36. }
  37. /**
  38. * @return bool
  39. */
  40. public function valid(): bool
  41. {
  42. return isset($this->values[$this->i]);
  43. }
  44. }