Completed
Push — master ( 6ea988...094374 )
by Eric
10:47
created

RecursiveGeneratorIterator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Oqq\Minc\Common\Iterator;
4
5
use RecursiveIterator;
6
7
/**
8
 * @author Eric Braun <[email protected]>
9
 */
10
class RecursiveGeneratorIterator implements \RecursiveIterator
11
{
12
    /** @var \Generator */
13
    protected $generator;
14
15
    /**
16
     * @param \Generator $generator
17
     */
18
    public function __construct(\Generator $generator)
19
    {
20
        $this->generator = $generator;
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function current()
27
    {
28
        return $this->generator->current();
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function next()
35
    {
36
        $this->generator->next();
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function key()
43
    {
44
        return $this->generator->key();
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    public function valid()
51
    {
52
        return $this->generator->valid();
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function rewind()
59
    {
60
        $this->generator->rewind();
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function hasChildren()
67
    {
68
        return $this->generator->current() instanceof \Generator;
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function getChildren()
75
    {
76
        return new self($this->generator->current());
77
    }
78
}
79