ChildlessRecursiveIterator::rewind()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SMW\Notifications\Iterators;
4
5
use Iterator;
6
use ArrayIterator;
7
use RecursiveIterator;
8
use RuntimeException;
9
10
/**
11
 * Pretends to be a RecursiveIterator without children
12
 *
13
 * @see EchoNotRecursiveIterator
14
 *
15
 * @license GNU GPL v2+
16
 * @since 1.0
17
 */
18
class ChildlessRecursiveIterator implements RecursiveIterator {
19
20
	/**
21
	 * @var Iterator
22
	 */
23
	protected $iterator;
24
25
	/**
26
	 * @since 1.0
27
	 *
28
	 * {@inheritDoc}
29
	 */
30 4
	public function __construct( $iterator ) {
31
32 4
		if ( is_array( $iterator ) ) {
33 3
			$iterator = new ArrayIterator( $iterator );
34
		}
35
36 4
		if ( !$iterator instanceof Iterator ) {
37 1
			throw new RuntimeException( "ChildlessRecursiveIterator expected an Iterator" );
38
		}
39
40 3
		$this->iterator = $iterator;
41 3
	}
42
43
	/**
44
	 * @since 1.0
45
	 *
46
	 * {@inheritDoc}
47
	 */
48 2
	public function current() {
49 2
		return $this->iterator->current();
50
	}
51
52
	/**
53
	 * @since 1.0
54
	 *
55
	 * {@inheritDoc}
56
	 */
57
	public function key() {
58
		return $this->iterator->key();
59
	}
60
61
	/**
62
	 * @since 1.0
63
	 *
64
	 * {@inheritDoc}
65
	 */
66 2
	public function next() {
67 2
		return $this->iterator->next();
68
	}
69
70
	/**
71
	 * @since 1.0
72
	 *
73
	 * {@inheritDoc}
74
	 */
75 2
	public function rewind() {
76 2
		return $this->iterator->rewind();
77
	}
78
79
	/**
80
	 * @since 1.0
81
	 *
82
	 * {@inheritDoc}
83
	 */
84 2
	public function valid() {
85 2
		return $this->iterator->valid();
86
	}
87
88
	/**
89
	 * @since 1.0
90
	 *
91
	 * {@inheritDoc}
92
	 */
93 1
	public function hasChildren() {
94 1
		return false;
95
	}
96
97
	/**
98
	 * @since 1.0
99
	 *
100
	 * {@inheritDoc}
101
	 */
102
	public function getChildren() {
103
		return null;
104
	}
105
106
}
107