Iterator::next()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Maphper;
4
5
class Iterator implements \Iterator {
6
	private $array;
7
	private $pk;
8
	private $iterator = 0;
9
10
	public function __construct(array $array, $pk) {
11
		$this->array = $array;
12
		$this->pk = $pk;
13
	}
14
15
	public function current() {
16
		return $this->array[$this->iterator];
17
	}
18
19
	public function key() {
20
		if (count($this->pk) == 1) {
21
			$pk = end($this->pk);
22
			return $this->array[$this->iterator]->$pk;
23
		}
24
		else {
25
			$current = $this->current();
26
			return array_map(function($pkName) use ($current) {
27
				return $current->$pkName;
28
			}, $this->pk);
29
		}
30
	}
31
32
	public function next() {
33
		++$this->iterator;
34
	}
35
36
	public function valid() {
37
		return isset($this->array[$this->iterator]);
38
	}
39
40
	public function rewind() {
41
		$this->iterator = 0;
42
	}
43
}
44