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.

InMemoryQueue   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 74.36%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A count() 0 6 1
A enqueue() 0 6 1
A dequeue() 0 12 2
A peek() 0 18 5
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