Completed
Push — master ( f5d71d...bfd9cb )
by Sam
12:52
created

DAG_Iterator::current()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 13
rs 9.4285
1
<?php
2
3
namespace SilverStripe\Core\Config;
4
5
use Iterator;
6
7
class DAG_Iterator implements Iterator
8
{
9
10
	protected $data;
11
	protected $dag;
12
13
	protected $dagkeys;
14
	protected $i;
15
16
	public function __construct($data, $dag)
17
	{
18
		$this->data = $data;
19
		$this->dag = $dag;
20
		$this->rewind();
21
	}
22
23
	public function key()
24
	{
25
		return $this->i;
26
	}
27
28
	public function current()
29
	{
30
		$res = array();
31
32
		$res['from'] = $this->data[$this->i];
33
34
		$res['to'] = array();
35
		foreach ($this->dag[$this->i] as $to) {
36
			$res['to'][] = $this->data[$to];
37
		}
38
39
		return $res;
40
	}
41
42
	public function next()
43
	{
44
		$this->i = array_shift($this->dagkeys);
45
	}
46
47
	public function rewind()
48
	{
49
		$this->dagkeys = array_keys($this->dag);
50
		$this->next();
51
	}
52
53
	public function valid()
54
	{
55
		return $this->i !== null;
56
	}
57
}
58