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

HashMapIterator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 44
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
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;
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