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.

UniqueIterator   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 25 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 0
dl 16
loc 64
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A rewind() 0 5 1
A filterAssumeUnsorted() 8 8 2
A filterAssumeSorted() 8 8 2
A filterCurrent() 0 4 1
A filterKey() 0 4 1
A accept() 0 6 3

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 UniqueIterator extends \FilterIterator
6
{
7
    protected $found;
8
    protected $callback;
9
    protected $method;
10
11
    const ASSUME_SORTED = 1;
12
    const REINDEX = 2;
13
    const UNIQUE_CURRENT = [__CLASS__, 'filterCurrent'];
14
    const UNIQUE_KEY = [__CLASS__, 'filterKey'];
15
16 8
    public function __construct(\Traversable $iterator, int $flags = 0, callable $callback = self::UNIQUE_CURRENT)
17
    {
18 8
        parent::__construct($iterator);
19 8
        $this->callback = \Closure::fromCallable($callback);
20
21 8
        if ($flags & self::ASSUME_SORTED) {
22 4
            $this->method = \Closure::fromCallable([$this, 'filterAssumeSorted']);
23
        } else {
24 4
            $this->method = \Closure::fromCallable([$this, 'filterAssumeUnsorted']);
25
        }
26 8
    }
27
28 7
    public function rewind()
29
    {
30 7
        $this->found = [];
31 7
        return parent::rewind();
32
    }
33
34 3 View Code Duplication
    public function filterAssumeUnsorted($key)
0 ignored issues
show
Duplication introduced by
This method 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...
35
    {
36 3
        if (isset($this->found[$key])) {
37 3
            return false;
38
        }
39 3
        $this->found[$key] = true;
40 3
        return true;
41
    }
42
43 4 View Code Duplication
    public function filterAssumeSorted($key)
0 ignored issues
show
Duplication introduced by
This method 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...
44
    {
45 4
        if (isset($this->found[$key])) {
46 4
            return false;
47
        }
48 4
        $this->found = [$key => true];
49 4
        return true;
50
    }
51
52 4
    public static function filterCurrent($iterator)
53
    {
54 4
        return $iterator->current();
55
    }
56
57 3
    public static function filterKey($iterator)
58
    {
59 3
        return $iterator->key();
60
    }
61
62 7
    public function accept()
63
    {
64 7
        $key = ($this->callback)($this->getInnerIterator());
65 7
        $key = is_scalar($key) ? $key : (is_object($key) ? spl_object_hash($key) : serialize($key));
66 7
        return ($this->method)($key);
67
    }
68
}
69