InMemoryQueue::peek()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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