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.

MapIterator   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 55
rs 10
c 0
b 0
f 0
ccs 29
cts 29
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A map() 0 18 5
A rewind() 0 6 1
A next() 0 5 1
A key() 0 4 1
A current() 0 4 1
1
<?php
2
3
namespace Gielfeldt\Iterators;
4
5
class MapIterator extends TraversableIterator
6
{
7
    protected $currentKey;
8
    protected $currentValue;
9
    protected $currentIdx;
10
    protected $callback;
11
12 8
    public function __construct(\Traversable $iterator, callable $callback)
13
    {
14 8
        parent::__construct($iterator);
15 8
        $this->callback = \Closure::fromCallable($callback);
16 8
    }
17
18 7
    private function map()
19
    {
20 7
        if ($this->valid()) {
21 7
            $result = ($this->callback)($this->getInnerIterator());
22 7
            if (is_array($result)) {
23 4
                list($this->currentKey, $this->currentValue) = $result;
24 4
                if (is_numeric($this->currentKey) && intval($this->currentKey) >= $this->currentIdx) {
25 2
                    $this->currentIdx = intval($this->currentKey) + 1;
26
                }
27
            } else {
28 3
                $this->currentKey = $this->currentIdx++;
29 3
                $this->currentValue = $result;
30
            }
31
        } else {
32 7
            $this->currentKey = null;
33 7
            $this->currentValue = null;
34
        }
35 7
    }
36
37 7
    public function rewind()
38
    {
39 7
        parent::rewind();
40 7
        $this->currentIdx = 0;
41 7
        $this->map();
42 7
    }
43
44 7
    public function next()
45
    {
46 7
        parent::next();
47 7
        $this->map();
48 7
    }
49
50 7
    public function key()
51
    {
52 7
        return $this->currentKey;
53
    }
54
55 7
    public function current()
56
    {
57 7
        return $this->currentValue;
58
    }
59
}
60