Completed
Push — master ( a3c7f3...e65d14 )
by Arnold
02:17
created

CombineIterator::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Improved\Iterator;
6
7
use function Improved\iterable_to_iterator;
8
9
/**
10
 * Iterator through keys and values, where key may be any type.
11
 */
12
class CombineIterator implements \Iterator
13
{
14
    /**
15
     * @var \Iterator
16
     */
17
    protected $keys;
18
19
    /**
20
     * @var \Iterator
21
     */
22
    protected $values;
23
24
    /**
25
     * Class constructor.
26
     *
27
     * @param iterable $keys
28
     * @param iterable $values
29
     */
30 11
    public function __construct(iterable $keys, iterable $values)
31
    {
32 11
        $this->keys = iterable_to_iterator($keys);
33 11
        $this->values = iterable_to_iterator($values);
34 11
    }
35
36
    /**
37
     * Get the current value.
38
     *
39
     * @return mixed
40
     */
41 9
    public function current()
42
    {
43 9
        return $this->values->current();
44
    }
45
46
    /**
47
     * Get the current key.
48
     *
49
     * @return mixed
50
     */
51 9
    public function key()
52
    {
53 9
        return $this->keys->current();
54
    }
55
56
    /**
57
     * Forward to the next element.
58
     *
59
     * @return void
60
     */
61 9
    public function next(): void
62
    {
63 9
        $this->keys->next();
64 9
        $this->values->next();
65 9
    }
66
67
    /**
68
     * Checks if the iterator is valid.
69
     *
70
     * @return bool
71
     */
72 10
    public function valid(): bool
73
    {
74 10
        return $this->keys->valid();
75
    }
76
77
    /**
78
     * Checks if the iterator is valid.
79
     *
80
     * @return void
81
     */
82 10
    public function rewind(): void
83
    {
84 10
        $this->keys->rewind();
85 10
        $this->values->rewind();
86 10
    }
87
}
88