ComplexityCollectionIterator.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of sebastian/complexity.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Complexity;
  11. use Iterator;
  12. final class ComplexityCollectionIterator implements Iterator
  13. {
  14. /**
  15. * @psalm-var list<Complexity>
  16. */
  17. private readonly array $items;
  18. private int $position = 0;
  19. public function __construct(ComplexityCollection $items)
  20. {
  21. $this->items = $items->asArray();
  22. }
  23. public function rewind(): void
  24. {
  25. $this->position = 0;
  26. }
  27. public function valid(): bool
  28. {
  29. return isset($this->items[$this->position]);
  30. }
  31. public function key(): int
  32. {
  33. return $this->position;
  34. }
  35. public function current(): Complexity
  36. {
  37. return $this->items[$this->position];
  38. }
  39. public function next(): void
  40. {
  41. $this->position++;
  42. }
  43. }