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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 68.42%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 49
ccs 13
cts 19
cp 0.6842
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A push() 0 5 1
A pop() 0 8 2
A get() 0 8 2
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