Completed
Push — master ( 887cf7...2ea773 )
by Emily
02:13
created

HashMapIterator::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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;
16
17
use Spaark\CompositeUtils\Traits\AutoConstructTrait;
18
19
/**
20
 * Iterator for the HashMap datatype
21
 *
22
 * @generic KeyType
23
 * @generic ValueType
24
 */
25
class HashMapIterator extends MapIterator
26
{
27
    use AutoConstructTrait;
28
29
    /**
30
     * @var Pair<KeyType, ValueType>[]
31
     * @construct required
32
     */
33
    protected $data;
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    public function getCurrent() : Pair
39
    {
40
        return current($this->data);
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46
    public function rewind()
47
    {
48
        reset($this->data);
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function valid()
55
    {
56
        return key($this->data) !== NULL;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function next()
63
    {
64
        $next = next($this->data);
65
66
        return $next ? $next->value : null;
67
    }
68
}
69