Completed
Branch master (339a46)
by Damian
04:14
created

InMemoryQueue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 33
ccs 11
cts 11
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 5 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\Exception\NoSuchElementException;
7
use Initx\Querabilis\Queue;
8
9
final class InMemoryQueue implements Queue
10
{
11
    use HasDefaultRemoveAndElement;
12
13
    /**
14
     * @var Envelope[]
15
     */
16
    private $items = [];
17
18 2
    public function add(Envelope $envelope): bool
19
    {
20 2
        return $this->offer($envelope);
21
    }
22
23 2
    public function offer(Envelope $envelope): bool
24
    {
25 2
        $this->items[] = $envelope;
26
27 2
        return true;
28
    }
29
30 2
    public function poll(): ?Envelope
31
    {
32 2
        $item = array_shift($this->items);
33
34 2
        return $item ?: null;
35
    }
36
37 2
    public function peek(): ?Envelope
38
    {
39 2
        $item = $this->items[0] ?? null;
40
41 2
        return $item;
42
    }
43
}
44