Code Duplication    Length = 35-35 lines in 2 locations

src/Zicht/Itertools/lib/DifferenceIterator.php 1 location

@@ 14-48 (lines=35) @@
11
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
12
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
13
14
class DifferenceIterator extends \FilterIterator implements FiniteIterableInterface
15
{
16
    use FiniteIterableTrait;
17
18
    /** @var \Closure */
19
    private $func;
20
21
    /** @var mixed[] */
22
    private $excludes;
23
24
    /**
25
     * @param \Iterator $iterable
26
     * @param \Iterator $excludesIterable
27
     * @param \Closure $func
28
     */
29
    public function __construct(\Iterator $iterable, \Iterator $excludesIterable, \Closure $func)
30
    {
31
        $this->func = $func;
32
        $this->excludes = Itertools\iterable($excludesIterable)->map($this->func)->values();
33
        parent::__construct($iterable);
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function accept()
40
    {
41
        return !in_array(
42
            call_user_func_array($this->func, [$this->current(), $this->key()]),
43
            $this->excludes
44
        );
45
    }
46
}
47

src/Zicht/Itertools/lib/IntersectionIterator.php 1 location

@@ 14-48 (lines=35) @@
11
use Zicht\Itertools\lib\Interfaces\FiniteIterableInterface;
12
use Zicht\Itertools\lib\Traits\FiniteIterableTrait;
13
14
class IntersectionIterator extends \FilterIterator implements FiniteIterableInterface
15
{
16
    use FiniteIterableTrait;
17
18
    /** @var \Closure */
19
    private $func;
20
21
    /** @var mixed[] */
22
    private $includes;
23
24
    /**
25
     * @param \Iterator $iterable
26
     * @param \Iterator $includesIterator
27
     * @param \Closure $func
28
     */
29
    public function __construct(\Iterator $iterable, \Iterator $includesIterator, \Closure $func)
30
    {
31
        $this->func = $func;
32
        $this->includes = Itertools\iterable($includesIterator)->map($this->func)->values();
33
        parent::__construct($iterable);
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function accept()
40
    {
41
        return in_array(
42
            call_user_func_array($this->func, [$this->current(), $this->key()]),
43
            $this->includes
44
        );
45
    }
46
}
47