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

Complexity

Conditions 5
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.3554
c 0
b 0
f 0
ccs 12
cts 12
cp 1
cc 5
nc 4
nop 0
crap 5
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