Total Complexity | 5 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class CallbackIterator implements Iterator |
||
11 | { |
||
12 | /** |
||
13 | * @var IterateResult |
||
14 | */ |
||
15 | private $currentIterateResult; |
||
16 | private $generator; |
||
17 | |||
18 | /** |
||
19 | * CallbackIterator constructor. |
||
20 | * @param $f callable Function with interface Fun(): IterateResult |
||
21 | */ |
||
22 | 13 | public function __construct(callable $f) |
|
25 | 13 | } |
|
26 | |||
27 | 13 | public function next() |
|
28 | { |
||
29 | 13 | if (!$this->hasNext()) { |
|
30 | 1 | throw new RuntimeException('Iterated element is absent'); |
|
31 | } |
||
32 | 13 | $value = $this->currentIterateResult->getValue(); |
|
33 | 13 | $this->currentIterateResult = null; |
|
34 | 13 | return $value; |
|
35 | } |
||
36 | |||
37 | 13 | public function hasNext(): bool |
|
44 | } |
||
45 | } |
||
46 |