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.

StreamFeedIterator::createInnerIterator()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 47
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 5

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 47
ccs 22
cts 22
cp 1
rs 8.5125
cc 5
eloc 28
nc 4
nop 0
crap 5
1
<?php
2
namespace EventStore\StreamFeed;
3
4
use ArrayIterator;
5
use EventStore\EventStoreInterface;
6
7
final class StreamFeedIterator implements \Iterator
8
{
9
    private $eventStore;
10
11
    private $streamName;
12
13
    private $feed;
14
15
    private $innerIterator;
16
17
    private $startingRelation;
18
19
    private $navigationRelation;
20
21
    private $arraySortingFunction;
22
23
    private $rewinded;
24
25 9
    private function __construct(
26
        EventStoreInterface $eventStore,
27
        $streamName,
28
        LinkRelation $startingRelation,
29
        LinkRelation $navigationRelation,
30
        callable $arraySortingFunction
31
    ) {
32 9
        $this->eventStore = $eventStore;
33 9
        $this->streamName = $streamName;
34 9
        $this->startingRelation = $startingRelation;
35 9
        $this->navigationRelation = $navigationRelation;
36 9
        $this->arraySortingFunction = $arraySortingFunction;
37 9
    }
38
39 5
    public static function forward(EventStoreInterface $eventStore, $streamName)
40
    {
41 5
        return new self(
42
            $eventStore,
43
            $streamName,
44 5
            LinkRelation::LAST(),
45 5
            LinkRelation::PREVIOUS(),
46 5
            'array_reverse'
47
        );
48
    }
49
50 4
    public static function backward(EventStoreInterface $eventStore, $streamName)
51
    {
52 4
        return new self(
53
            $eventStore,
54
            $streamName,
55 4
            LinkRelation::FIRST(),
56 4
            LinkRelation::NEXT(),
57
            function (array $array) {
58 3
                return $array;
59 4
            }
60
        );
61
    }
62
63 5
    public function current()
64
    {
65 5
        return $this->innerIterator->current();
66
    }
67
68 6
    public function next()
69
    {
70 6
        $this->rewinded = false;
71 6
        $this->innerIterator->next();
72
73 6
        if (!$this->innerIterator->valid()) {
74 6
            $this->feed = $this
75 6
                ->eventStore
76 6
                ->navigateStreamFeed(
77 6
                    $this->feed,
78 6
                    $this->navigationRelation
79
                )
80
            ;
81
82 6
            $this->createInnerIterator();
83
        }
84 6
    }
85
86 5
    public function key()
87
    {
88 5
        return $this->innerIterator->current()->getEntry()->getTitle();
89
    }
90
91 6
    public function valid()
92
    {
93 6
        return $this->innerIterator->valid();
94
    }
95
96 7
    public function rewind()
97
    {
98 7
        if ($this->rewinded) {
99 1
            return;
100
        }
101
102 7
        $this->feed = $this->eventStore->openStreamFeed($this->streamName);
103
104 7
        if ($this->feed->hasLink($this->startingRelation)) {
105 6
            $this->feed = $this
106 6
                ->eventStore
107 6
                ->navigateStreamFeed(
108 6
                    $this->feed,
109 6
                    $this->startingRelation
110
                )
111
            ;
112
        }
113
114 7
        $this->createInnerIterator();
115
116 7
        $this->rewinded = true;
117 7
    }
118
119 7
    private function createInnerIterator()
120
    {
121 7
        if (null !== $this->feed) {
122 7
            $entries = $this->feed->getEntries();
123
        } else {
124 2
            $entries = [];
125
        }
126
127 7
        if (empty($entries)) {
128 6
            $this->innerIterator = new ArrayIterator([]);
129
130 6
            return;
131
        }
132
133 7
        $entries = call_user_func(
134 7
            $this->arraySortingFunction,
135
            $entries
136
        );
137
138 7
        $urls = array_map(
139
            function ($entry) {
140 7
                return $entry->getEventUrl();
141 7
            },
142
            $entries
143
        );
144
145 7
        $this->innerIterator = new ArrayIterator(
146
            array_filter(
147
                array_map(
148
                    function ($entry, $event) {
149 7
                        if ($entry === null || $event === null) {
150 1
                            return null;
151
                        }
152 7
                        return new EntryWithEvent(
153
                            $entry,
154
                            $event
155
                        );
156 7
                    },
157
                    $entries,
158 7
                    $this->eventStore->readEventBatch($urls)
0 ignored issues
show
Bug introduced by
The method readEventBatch() does not exist on EventStore\EventStoreInterface. Did you maybe mean readEvent()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
159
                ),
160 7
                function ($entryWithEvent) {
161 7
                    return ($entryWithEvent !== null);
162 7
                }
163
            )
164
        );
165 7
    }
166
}
167