Completed
Push — master ( 79f24a...4b5497 )
by Emily
02:16
created

HashMapIterator::next()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Model\Collection\Map;
16
17
/**
18
 * Iterator for the HashMap datatype
19
 *
20
 * @generic KeyType
21
 * @generic ValueType
22
 */
23
class HashMapIterator extends MapIterator
24
{
25
    /**
26
     * @var Pair<KeyType, ValueType>[]
27
     * @construct required
28
     */
29
    protected $data;
30
31
    /**
32
     * @var Pair<KeyType, ValueType>[]
33
     */
34 15
    public function __construct($data)
35
    {
36 15
        $this->data = $data;
37 15
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 11
    public function getCurrent() : Pair
43
    {
44 11
        return current($this->data);
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 15
    public function rewind()
51
    {
52 15
        reset($this->data);
53 15
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58 15
    public function valid()
59
    {
60 15
        return key($this->data) !== NULL;
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66 9
    public function next()
67
    {
68 9
        $next = next($this->data);
69
70 9
        return $next ? $next->value : null;
71
    }
72
}
73