コアサーバーV2プランご契約でドメイン更新費用が永久無料
 
Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
GeneratorIterator
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
6 / 6
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 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 Generator;
8use Iterator;
9use PeServer\Core\Throws\ArgumentException;
10use PeServer\Core\Throws\CallbackTypeError;
11
12/**
13 * ジェネレータ イテレータ。
14 *
15 * @template TKey of array-key
16 * @template TValue
17 * @implements Iterator<TKey,TValue>
18 */
19class GeneratorIterator implements Iterator
20{
21    #region variable
22
23    private Generator $generator;
24
25    #endregion
26
27    /**
28     * 生成。
29     *
30     * @param mixed $factory
31     * @phpstan-param callable():Generator<TKey,TValue> $factory
32     */
33    public function __construct(
34        private mixed $factory
35    ) {
36        if (!is_callable($factory)) { //@phpstan-ignore-line phpstan-param callable
37            throw new CallbackTypeError('$factory');
38        }
39        $this->generator = call_user_func($this->factory);
40    }
41
42    #region Iterator
43
44    public function rewind(): void
45    {
46        $this->generator = call_user_func($this->factory);
47    }
48
49    public function key(): mixed
50    {
51        return $this->generator->key();
52    }
53
54    public function current(): mixed
55    {
56        return $this->generator->current();
57    }
58
59    public function next(): void
60    {
61        $this->generator->next();
62    }
63
64    public function valid(): bool
65    {
66        return $this->generator->valid();
67    }
68
69    #endregion
70}