InMemoryQueue   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 31
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offer() 0 5 1
A peek() 0 3 1
A poll() 0 5 2
A add() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Initx\Querabilis\Driver;
4
5
use Initx\Querabilis\Envelope;
6
use Initx\Querabilis\Queue;
7
8
final class InMemoryQueue implements Queue
9
{
10
    use HasDefaultRemoveAndElement;
11
12
    /**
13
     * @var Envelope[]
14
     */
15
    private $items = [];
16
17 2
    public function add(Envelope $envelope): bool
18
    {
19 2
        return $this->offer($envelope);
20
    }
21
22 2
    public function offer(Envelope $envelope): bool
23
    {
24 2
        $this->items[] = $envelope;
25
26 2
        return true;
27
    }
28
29 2
    public function poll(): ?Envelope
30
    {
31 2
        $item = array_shift($this->items);
32
33 2
        return $item ?: null;
34
    }
35
36 2
    public function peek(): ?Envelope
37
    {
38 2
        return $this->items[0] ?? null;
39
    }
40
}
41