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.
Completed
Push — master ( 967239...06466a )
by Márk
02:52
created

InMemoryQueue::peek()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.246

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 11
cts 14
cp 0.7856
rs 9.3554
c 0
b 0
f 0
cc 5
nc 3
nop 2
crap 5.246
1
<?php
2
3
namespace Bernard\Queue;
4
5
use Bernard\Envelope;
6
7
/**
8
 * Wrapper around SplQueue.
9
 */
10
class InMemoryQueue extends AbstractQueue
11
{
12
    protected $queue;
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 36
    public function __construct($name)
18
    {
19 36
        parent::__construct($name);
20
21 36
        $this->queue = new \SplQueue();
22 36
        $this->queue->setIteratorMode(\SplQueue::IT_MODE_DELETE);
23 36
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 17
    public function count()
29
    {
30 17
        $this->errorIfClosed();
31
32 16
        return $this->queue->count();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 17
    public function enqueue(Envelope $envelope)
39
    {
40 17
        $this->errorIfClosed();
41
42 16
        $this->queue->enqueue($envelope);
43 16
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 15
    public function dequeue()
49
    {
50 15
        $this->errorIfClosed();
51
52 14
        if ($this->count()) {
53 12
            return $this->queue->dequeue();
54
        }
55
56 7
        usleep(10000);
57
58 7
        return;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 4
    public function peek($index = 0, $limit = 20)
65
    {
66 4
        $this->errorIfClosed();
67
68 2
        $envelopes = [];
69 2
        $queue = clone $this->queue;
70 2
        $key = 0;
71
72 2
        while ($queue->count() && count($envelopes) < $limit && $envelope = $queue->dequeue()) {
73 2
            if ($key++ < $index) {
74 1
                continue;
75
            }
76
77 2
            $envelopes[] = $envelope;
78 2
        }
79
80 2
        return $envelopes;
81
    }
82
}
83