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

HashMapIterator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 50
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCurrent() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
A next() 0 6 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