Stencil_Abstract_Hierarchy::current()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jip
5
 * Date: 27/12/15
6
 * Time: 16:47
7
 *
8
 * @package Stencil
9
 */
10
11
/**
12
 * Class AbstractHierarchy
13
 */
14
abstract class Stencil_Abstract_Hierarchy implements Iterator {
15
	/**
16
	 * Current index
17
	 *
18
	 * @var int
19
	 */
20
	protected $index = 0;
21
22
	/**
23
	 * The options for this item
24
	 *
25
	 * @var array
26
	 */
27
	protected $options = array();
28
29
	/**
30
	 * Set the options
31
	 *
32
	 * @param array $options Set the options available.
33
	 */
34
	protected function set_options( $options ) {
35
		$this->options = $options;
36
	}
37
38
	/**
39
	 * Return the current element
40
	 * @link http://php.net/manual/en/iterator.current.php
41
	 * @return mixed Can return any type.
42
	 * @since 5.0.0
43
	 */
44
	public function current() {
45
		return $this->options[ $this->index ];
46
	}
47
48
	/**
49
	 * Move forward to next element
50
	 */
51
	public function next() {
52
		++ $this->index;
53
	}
54
55
	/**
56
	 * Return the key of the current element
57
	 *
58
	 * @return mixed|null scalar on success, null on failure.
59
	 */
60
	public function key() {
61
		return $this->index;
62
	}
63
64
	/**
65
	 * Checks if current position is valid
66
	 *
67
	 * Returns true on success or false on failure.
68
	 */
69
	public function valid() {
70
		return isset( $this->options[ $this->index ] );
71
	}
72
73
	/**
74
	 * Rewind the Iterator to the first element
75
	 */
76
	public function rewind() {
77
		$this->index = 0;
78
	}
79
}
80