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.

PrefetchMessageCache::pop()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0932
1
<?php
2
3
namespace Bernard\Driver;
4
5
class PrefetchMessageCache
6
{
7
    protected $caches = [];
8
9
    /**
10
     * Pushes a $message to the end of the cache.
11
     *
12
     * @param string $queueName
13
     * @param array  $message
14
     */
15 5
    public function push($queueName, array $message)
16
    {
17 5
        $cache = $this->get($queueName);
18 5
        $cache->enqueue($message);
19 5
    }
20
21
    /**
22
     * Get the next message in line. Or nothing if there is no more
23
     * in the cache.
24
     *
25
     * @param string $queueName
26
     *
27
     * @return array|null
28
     */
29 6
    public function pop($queueName)
30
    {
31 6
        $cache = $this->get($queueName);
32
33 6
        if (!$cache->isEmpty()) {
34 5
            return $cache->dequeue();
35
        }
36 6
    }
37
38
    /**
39
     * Create the queue cache internally if it doesn't yet exists.
40
     *
41
     * @param string $queueName
42
     *
43
     * @return \SplQueue
44
     */
45 6
    protected function get($queueName)
46
    {
47 6
        if (isset($this->caches[$queueName])) {
48 5
            return $this->caches[$queueName];
49
        }
50
51 6
        return $this->caches[$queueName] = new \SplQueue();
52
    }
53
}
54