Passed
Push — master ( 9e9b54...8c04f5 )
by
unknown
38s
created

DifferenceIterator::accept()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib;
8
9
use Zicht\Itertools;
10
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
11
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
12
13
/**
14
 * Class DifferenceIterator
15
 *
16
 * @package Zicht\Itertools\lib
17
 */
18
class DifferenceIterator extends \FilterIterator implements FiniteIterableInterface
19
{
20
    use FiniteIterableTrait;
21
22
    /** @var \Closure */
23
    private $func;
24
25
    /** @var mixed[] */
26
    private $excludes;
27
28
    /**
29
     * DifferenceIterator constructor.
30
     *
31
     * @param \Iterator $iterable
32
     * @param \Iterator $excludesIterable
33
     * @param \Closure $func
34
     */
35 7
    public function __construct(\Iterator $iterable, \Iterator $excludesIterable, \Closure $func)
36
    {
37 7
        $this->func = $func;
38 7
        $this->excludes = Itertools\iterable($excludesIterable)->map($this->func)->values();
39 7
        parent::__construct($iterable);
40 7
    }
41
42
    /**
43
     * @{inheritDoc}
44
     */
45 4
    public function accept()
46
    {
47 4
        return !in_array(
48 4
            call_user_func_array($this->func, [$this->current(), $this->key()]),
49 4
            $this->excludes
50
        );
51
    }
52
}
53