ReadOnlyIterator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 77
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A next() 0 3 1
A valid() 0 3 1
A key() 0 3 1
A __construct() 0 3 1
A rewind() 0 3 1
1
<?php
2
/**
3
 * Incoming
4
 *
5
 * @author    Trevor Suarez (Rican7)
6
 * @copyright (c) Trevor Suarez
7
 * @link      https://github.com/Rican7/incoming
8
 * @license   MIT
9
 */
10
11
declare(strict_types=1);
12
13
namespace Incoming\Structure\Iterator;
14
15
use Iterator;
16
17
/**
18
 * A very basic iterator implementation that decorates another iterator but only
19
 * allows the most basic of iterator operations without having access to the
20
 * underlying iterator.
21
 */
22
final class ReadOnlyIterator implements Iterator
23
{
24
25
    /**
26
     * Properties
27
     */
28
29
    /**
30
     * The underlying decorated iterator.
31
     *
32
     * @var Iterator
33
     */
34
    private $decorated;
35
36
37
    /**
38
     * Methods
39
     */
40
41
    /**
42
     * Constructor
43
     *
44
     * @param Iterator $decorated The iterator to decorate as read-only.
45
     */
46 36
    public function __construct(Iterator $decorated)
47
    {
48 36
        $this->decorated = $decorated;
49 36
    }
50
51
    /**
52
     * Return the current element.
53
     *
54
     * @return mixed The current element.
55
     */
56 36
    public function current()
57
    {
58 36
        return $this->decorated->current();
59
    }
60
61
    /**
62
     * Return the key of the current element.
63
     *
64
     * @return scalar The key of the current element.
65
     */
66 33
    public function key()
67
    {
68 33
        return $this->decorated->key();
69
    }
70
71
    /**
72
     * Move forward to next element.
73
     *
74
     * @return void
75
     */
76 36
    public function next()
77
    {
78 36
        $this->decorated->next();
79 36
    }
80
81
    /**
82
     * Rewind the Iterator to the first element.
83
     *
84
     * @return void
85
     */
86 36
    public function rewind()
87
    {
88 36
        $this->decorated->rewind();
89 36
    }
90
91
    /**
92
     * Checks if current position is valid.
93
     *
94
     * @return bool True if the current position is valid, false otherwise.
95
     */
96 36
    public function valid(): bool
97
    {
98 36
        return $this->decorated->valid();
99
    }
100
}
101