CallbackFilterIterator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Methods

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