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