http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 8 LOC: 119 Statements: 18

Source file Statements Methods Total coverage
Iterator.php 94.4% 100.0% 96.2%
   
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * This source file is subject to the new BSD license that is bundled
6
 * with this package in the file LICENSE.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.opensource.org/licenses/bsd-license.php
9
 *
10
 * @category  Xyster
11
 * @package   Xyster_Collection
12
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 */
15
/**
16
 * Iterator for collections
17
 *
18
 * @category  Xyster
19
 * @package   Xyster_Collection
20
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
21
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
22
 */
23
class Xyster_Collection_Iterator implements SeekableIterator, Countable
24
{
25
	/**
26
	 * The array over which to iterate
27
	 *
28
	 * @var array
29
	 */
30
	protected $_items;
31
32
	/**
33
	 * Creates a new iterator
34
	 *
35
	 * @param array $list  An array to iterate
36
	 */
37
	public function __construct( array $list )
38
	{
39 236
		$this->_items = $list;
40
	}
41
42
	/**
43
	 * Counts the number of elements
44
	 *
45
	 * @return int  Number of elements in collection
46
	 */
47
	public function count()
48
	{
49 1
		return count($this->_items);
50
	}
51
52
	/**
53
	 * Return the current element
54
	 *
55
	 * @return mixed  The current element
56
	 */
57
    public function current()
58
    {
59 232
        return current($this->_items);
60
    }
61
62
	/**
63
	 * Return the key of the current element
64
	 *
65
	 * @return mixed  Key of the current element
66
	 */
67
    public function key()
68
    {
69 21
        return key($this->_items);
70
    }
71
72
	/**
73
	 * Move pointer forward to next element
74
	 *
75
	 */
76
    public function next()
77
    {
78 206
        next($this->_items);
79
    }
80
81
	/**
82
	 * Rewind the pointer to the first element
83
	 *
84
	 */
85
    public function rewind()
86
    {
87 230
        reset($this->_items);
88
    }
89
90
	/**
91
	 * Check if there is a current element after calls to rewind() or next()
92
	 *
93
	 * @return boolean
94
	 */
95
    public function valid()
96
    {
97 230
        return ( $this->current() !== false );
98
    }
99
100
	/**
101
	 * Seek to an absolute position.
102
	 *
103
	 * @param int $index  Position to seek
104
	 * @throws Xyster_Collection_Exception  if the seek position is not found
105
	 */
106
 	public function seek( $index )
107
 	{
108 1
		$this->rewind();
109 1
		$position = 0;
110 1
		while( $position < $index && $this->valid() ) {
111 1
			$this->next();
112 1
			$position++;
113 1
		}
114 1
		if ( !$this->valid() ) {
115 1
		    require_once 'Xyster/Collection/Exception.php';
116 1
			throw new Xyster_Collection_Exception('Out of bounds');
117 0
		}
118
 	}
119
}


Report generated at 2008-03-05T18:27:43-05:00