CallbackFilterIterator::accept()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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