Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
RepeatIterator
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 rewind
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 key
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 current
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 next
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 valid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\Collection;
6
7use Iterator;
8
9/**
10 * repeat イテレータ。
11 *
12 * @template TValue
13 * @implements Iterator<non-negative-int,TValue>
14 */
15class RepeatIterator implements Iterator
16{
17    #region variable
18
19    /** @phpstan-var non-negative-int */
20    private int $key = 0;
21
22    #endregion
23
24    /**
25     * 生成。
26     *
27     * @param mixed $value
28     * @param int $count
29     * @phpstan-param non-negative-int $count
30     */
31    public function __construct(
32        private mixed $value,
33        private int $count
34    ) {
35    }
36
37    #region Iterator
38
39    public function rewind(): void
40    {
41        $this->key = 0;
42    }
43
44    /**
45     * @return int
46     * @phpstan-return non-negative-int
47     */
48    public function key(): mixed
49    {
50        return $this->key;
51    }
52
53    /**
54     * @phpstan-return TValue
55     */
56    public function current(): mixed
57    {
58        return $this->value;
59    }
60
61    public function next(): void
62    {
63        $this->key += 1;
64    }
65
66    public function valid(): bool
67    {
68        return $this->key < $this->count;
69    }
70
71    #endregion
72}