Total Complexity | 9 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
9 | final class InMemoryQueue implements Queue |
||
10 | { |
||
11 | /** |
||
12 | * @var Envelope[] |
||
13 | */ |
||
14 | private $items = []; |
||
15 | |||
16 | 2 | public function add(Envelope $envelope): bool |
|
17 | { |
||
18 | 2 | return $this->offer($envelope); |
|
19 | } |
||
20 | |||
21 | 2 | public function offer(Envelope $envelope): bool |
|
26 | } |
||
27 | |||
28 | 2 | public function remove(): Envelope |
|
37 | } |
||
38 | |||
39 | 2 | public function poll(): ?Envelope |
|
40 | { |
||
41 | 2 | $item = array_shift($this->items); |
|
42 | |||
43 | 2 | return $item ?: null; |
|
44 | } |
||
45 | |||
46 | 2 | public function element(): Envelope |
|
47 | { |
||
48 | 2 | $envelope = $this->peek(); |
|
49 | |||
50 | 2 | if (!$envelope) { |
|
51 | 1 | throw new NoSuchElementException(); |
|
52 | } |
||
53 | |||
54 | 1 | return $envelope; |
|
55 | } |
||
56 | |||
57 | 2 | public function peek(): ?Envelope |
|
62 | } |
||
63 | } |
||
64 |