Completed
Push — master ( 5fb784...aeecf5 )
by mw
03:08
created

ChildlessRecursiveIterator   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 89
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A key() 0 3 1
A next() 0 3 1
A rewind() 0 3 1
A valid() 0 3 1
A hasChildren() 0 3 1
A getChildren() 0 3 1
A __construct() 0 12 3
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