DropWhileIterator::accept()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace itertools;
4
5
use InvalidArgumentException;
6
use FilterIterator;
7
use Iterator;
8
9
10
class DropWhileIterator extends FilterIterator
11
{
12
	protected $callback;
13
	protected $hasFailed;
14
15
	public function __construct($iterator, $callback)
16
	{
17
		parent::__construct(IterUtil::asIterator($iterator));
18
		if(!is_callable($callback)) {
19
			throw new InvalidArgumentException('No valid callback provided');
20
		}
21
		$this->callback = $callback;
22
		$this->hasFailed = false;
23
	}
24
25
	public function accept()
26
	{
27
		if($this->hasFailed) {
28
			return $this->hasFailed;
29
		}
30
		$this->hasFailed = ! call_user_func($this->callback, $this->current(), $this->key(), $this->getInnerIterator());
31
		return $this->hasFailed;
32
	}
33
}
34
35