SeekableIteratorTrait::seek()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Trait SeekableIteratorTrait
4
 *
5
 * @filesource   SeekableIteratorTrait.php
6
 * @created      04.12.2017
7
 * @package      chillerlan\Traits
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Traits\SPL;
14
15
use chillerlan\Traits\Interfaces\IteratorTrait;
16
use OutOfBoundsException;
17
18
/**
19
 * @extends \Iterator
20
 * @implements \SeekableIterator
21
 *
22
 * @link http://php.net/manual/class.seekableiterator.php
23
 */
24
trait SeekableIteratorTrait{
25
	use IteratorTrait;
26
27
	/**
28
	 * @link  http://php.net/manual/seekableiterator.seek.php
29
	 * @inheritdoc
30
	 */
31
	public function seek($pos):void{
32
		$this->rewind();
33
34
		for( ; $this->offset < $pos; ){
35
36
			if(!\next($this->array)) {
37
				throw new OutOfBoundsException('invalid seek position: '.$pos);
38
			}
39
40
			$this->offset++;
41
		}
42
43
	}
44
45
}
46