Completed
Push — master ( 703b67...f51a8f )
by Emily
02:01
created

HashMapIterator::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 2
    public function getCurrent() : Pair
39
    {
40 2
        return current($this->data);
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46 3
    public function rewind()
47
    {
48 3
        reset($this->data);
49 3
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 3
    public function valid()
55
    {
56 3
        return key($this->data) !== NULL;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62 1
    public function next()
63
    {
64 1
        $next = next($this->data);
65
66 1
        return $next ? $next->value : null;
67
    }
68
}
69