Passed
Push — master ( 8c04f5...80d259 )
by
unknown
04:51 queued 32s
created

IntersectionIterator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 35
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() 6 6 1
A accept() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 IntersectionIterator
15
 *
16
 * @package Zicht\Itertools\lib
17
 */
18 View Code Duplication
class IntersectionIterator extends \FilterIterator implements FiniteIterableInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    use FiniteIterableTrait;
21
22
    /** @var \Closure */
23
    private $func;
24
25
    /** @var mixed[] */
26
    private $includes;
27
28
    /**
29
     * IntersectionIterator constructor.
30
     *
31
     * @param \Iterator $iterable
32
     * @param \Iterator $includesIterator
33
     * @param \Closure $func
34
     */
35 9
    public function __construct(\Iterator $iterable, \Iterator $includesIterator, \Closure $func)
36
    {
37 9
        $this->func = $func;
38 9
        $this->includes = Itertools\iterable($includesIterator)->map($this->func)->values();
39 9
        parent::__construct($iterable);
40 9
    }
41
42
    /**
43
     * @{inheritDoc}
44
     */
45 6
    public function accept()
46
    {
47 6
        return in_array(
48 6
            call_user_func_array($this->func, [$this->current(), $this->key()]),
49 6
            $this->includes
50
        );
51
    }
52
}
53