Passed
Push — master ( 8a631f...a79a09 )
by Zoilo
01:53
created

MemoryErrorPool   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findAndDelete() 0 15 3
A put() 0 3 1
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Pool\Memory;
4
5
use ZoiloMora\ElasticAPM\Events\Error\Error;
6
use ZoiloMora\ElasticAPM\Events\Transaction\Transaction;
7
use ZoiloMora\ElasticAPM\Pool\ErrorPool;
8
9
final class MemoryErrorPool extends MemoryPool implements ErrorPool
10
{
11
    /**
12
     * @param Error $item
13
     *
14
     * @return void
15
     */
16
    public function put(Error $item)
17
    {
18
        $this->items[] = $item;
19
    }
20
21
    /**
22
     * @param Transaction $transaction
23
     *
24
     * @return Error[]
25
     */
26
    public function findAndDelete(Transaction $transaction)
27
    {
28
        $result = [];
29
30
        /** @var Error $item */
31
        foreach ($this->items as $key => $item) {
32
            if ($item->transactionId() !== $transaction->id()) {
33
                continue;
34
            }
35
36
            $result[] = $item;
37
            unset($this->items[$key]);
38
        }
39
40
        return $result;
41
    }
42
}
43