DropWhileIterator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A accept() 0 8 2
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