Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
12 / 12
DictionaryIterator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
12 / 12
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 current
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 next
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 key
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 valid
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 rewind
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
1<?php
2
3namespace GamingEngine\Dictionary;
4
5use Iterator;
6
7/**
8 * Iterator for Dictionary collection
9 */
10class DictionaryIterator implements Iterator
11{
12    /**
13     * @var array
14     */
15    private array $data = [];
16
17    /**
18     * @var string[]
19     */
20    private array $keys = [];
21
22    /**
23     * DictionaryIterator constructor.
24     * @param Dictionary $dictionary
25     */
26    public function __construct(Dictionary $dictionary)
27    {
28        $this->data = $dictionary->values();
29        $this->keys = $dictionary->keys();
30    }
31
32    /**
33     * {@inheritdoc}
34     */
35    public function current()
36    {
37        return current($this->data);
38    }
39
40    /**
41     * {@inheritdoc}
42     */
43    public function next()
44    {
45        next($this->data);
46        next($this->keys);
47    }
48
49    /**
50     * {@inheritdoc}
51     */
52    public function key()
53    {
54        return current($this->keys);
55    }
56
57    /**
58     * {@inheritdoc}
59     */
60    public function valid()
61    {
62        return key($this->data) !== null;
63    }
64
65    /**
66     * {@inheritdoc}
67     */
68    public function rewind()
69    {
70        reset($this->data);
71        reset($this->keys);
72    }
73}