Completed
Push — master ( 747a6a...c6c655 )
by Ítalo
02:55
created

LazyTakeWhileKeyedIterator::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Collections\Iterator;
4
5
class LazyTakeWhileKeyedIterator implements \Iterator
6
{
7
    /**
8
     * @var \Iterator
9
     */
10
    private $it;
11
12
    /**
13
     * @var callable
14
     */
15
    private $fn;
16
17
    public function __construct($it, $fn)
18
    {
19
        $this->it = $it;
20
        $this->fn = $fn;
21
    }
22
23
    public function __clone()
24
    {
25
        $this->it = clone $this->it;
26
    }
27
28
    public function rewind()
29
    {
30
        $this->it->rewind();
31
    }
32
33
    public function valid()
34
    {
35
        $it = $this->it;
36
        $fn = $this->fn;
37
38
        return ($it->valid() && $fn($it->current()));
39
    }
40
41
    public function next()
42
    {
43
        $this->it->next();
44
    }
45
46
    public function key()
47
    {
48
        return $this->it->key();
49
    }
50
51
    public function current()
52
    {
53
        return $this->it->current();
54
    }
55
}
56