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

DifferenceIterator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

2 Methods

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