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

MemoryErrorPool::findAndDelete()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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