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::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
ccs 7
cts 7
cp 1
cc 2
nc 2
nop 3
crap 2
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