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

DAG_Iterator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 7
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A key() 0 4 1
A current() 0 13 2
A next() 0 4 1
A rewind() 0 5 1
A valid() 0 4 1
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