GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DiffIterator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 42
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 7
loc 42
rs 10
c 0
b 0
f 0
ccs 20
cts 20
cp 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A setDiff() 0 4 1
A accept() 7 11 4
A diffCurrent() 0 4 1
A diffKey() 0 4 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
namespace Gielfeldt\Iterators;
4
5
class DiffIterator extends \FilterIterator
6
{
7
    protected $iterators;
8
    protected $callback;
9
10 6
    public function __construct(\Traversable ...$iterators)
11
    {
12 6
        $innerIterator = array_shift($iterators);
13 6
        parent::__construct($innerIterator);
14 6
        foreach ($iterators as $iterator) {
15 6
            $this->iterators[] = new CachingIterator($iterator);
16
        }
17 6
        $this->callback = \Closure::fromCallable([static::class, 'diffCurrent']);
18 6
    }
19
20 4
    public function setDiff(callable $callback)
21
    {
22 4
        $this->callback = \Closure::fromCallable($callback);
23 4
    }
24
25 3
    public function accept()
26
    {
27 3 View Code Duplication
        foreach ($this->iterators as $iterator) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
28 3
            foreach ($iterator as $key => $value) {
29 3
                if (($this->callback)($this->getInnerIterator(), $key, $value)) {
30 3
                    return false;
31
                }
32
            }
33
        }
34 3
        return true;
35
    }
36
37 2
    public static function diffCurrent($iterator, $key, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39 2
        return $iterator->current() == $value;
40
    }
41
42 2
    public static function diffKey($iterator, $key, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44 2
        return $iterator->key() == $key;
45
    }
46
}
47