CombineIterator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 74
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A valid() 0 3 1
A next() 0 4 1
A key() 0 3 1
A __construct() 0 4 1
A rewind() 0 4 1
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
0 ignored issues
show
introduced by
Class Improved\Iterator\CombineIterator implements generic interface Iterator but does not specify its types: TKey, TValue
Loading history...
13
{
14
    /**
15
     * @var \Iterator
16
     */
17
    protected $keys;
0 ignored issues
show
introduced by
Property Improved\Iterator\CombineIterator::$keys type has no value type specified in iterable type Iterator.
Loading history...
18
19
    /**
20
     * @var \Iterator
21
     */
22
    protected $values;
0 ignored issues
show
introduced by
Property Improved\Iterator\CombineIterator::$values type has no value type specified in iterable type Iterator.
Loading history...
23
24
    /**
25
     * Class constructor.
26
     *
27
     * @param iterable $keys
28
     * @param iterable $values
29
     */
30 11
    public function __construct(iterable $keys, iterable $values)
0 ignored issues
show
introduced by
Method Improved\Iterator\CombineIterator::__construct() has parameter $keys with no value type specified in iterable type iterable.
Loading history...
introduced by
Method Improved\Iterator\CombineIterator::__construct() has parameter $values with no value type specified in iterable type iterable.
Loading history...
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