AuthorCollectionIterator.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php declare(strict_types = 1);
  2. /*
  3. * This file is part of PharIo\Manifest.
  4. *
  5. * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, 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 PharIo\Manifest;
  11. class AuthorCollectionIterator implements \Iterator {
  12. /** @var Author[] */
  13. private $authors;
  14. /** @var int */
  15. private $position = 0;
  16. public function __construct(AuthorCollection $authors) {
  17. $this->authors = $authors->getAuthors();
  18. }
  19. public function rewind(): void {
  20. $this->position = 0;
  21. }
  22. public function valid(): bool {
  23. return $this->position < \count($this->authors);
  24. }
  25. public function key(): int {
  26. return $this->position;
  27. }
  28. public function current(): Author {
  29. return $this->authors[$this->position];
  30. }
  31. public function next(): void {
  32. $this->position++;
  33. }
  34. }