AbstractArrayIterator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 85
ccs 18
cts 20
cp 0.9
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A valid() 0 6 2
A current() 0 4 1
A next() 0 4 1
A rewind() 0 4 1
A count() 0 4 1
A key() 0 4 1
A isEmpty() 0 4 1
1
<?php
2
/**
3
 * This file is part of Phiremock.
4
 *
5
 * Phiremock is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * Phiremock is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with Phiremock.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Domain;
20
21
class AbstractArrayIterator implements \Iterator, \Countable
22
{
23
    /**
24
     * @var array
25
     */
26
    protected $array;
27
28 6
    public function __construct(array $array = [])
29
    {
30 6
        $this->array = $array;
31 6
    }
32
33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @see \Iterator::next()
37
     */
38 6
    #[\ReturnTypeWillChange]
39
    public function next()
40 6
    {
41 6
        next($this->array);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     *
47
     * @see \Iterator::valid()
48 6
     */
49
    #[\ReturnTypeWillChange]
50 6
    public function valid()
51
    {
52 6
        $key = key($this->array);
53
54
        return false !== $key && null !== $key;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     *
60 6
     * @see \Iterator::current()
61
     */
62 6
    #[\ReturnTypeWillChange]
63
    public function current()
64
    {
65
        return current($this->array);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70 6
     *
71
     * @see \Iterator::rewind()
72 6
     */
73 6
    #[\ReturnTypeWillChange]
74
    public function rewind()
75
    {
76
        reset($this->array);
77
    }
78
79
    /**
80 6
     * {@inheritdoc}
81
     *
82 6
     * @see \Iterator::key()
83
     */
84
    #[\ReturnTypeWillChange]
85
    public function key()
86
    {
87
        return key($this->array);
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     *
93
     * @see \Countable::count()
94
     */
95
    #[\ReturnTypeWillChange]
96 6
    public function count()
97
    {
98 6
        return \count($this->array);
99
    }
100
101
    /** @return bool */
102
    #[\ReturnTypeWillChange]
103
    public function isEmpty()
104
    {
105
        return empty($this->array);
106
    }
107
}
108