Passed
Push — master ( 82efe3...775557 )
by Paweł
03:11
created

Inventory::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Inventory;
6
7
use AardsGerds\Game\Shared\Collection;
8
9
final class Inventory extends Collection
10
{
11 1
    public function filterUsable(): self
12
    {
13 1
        return $this->filter(
14 1
            static fn(InventoryItem $inventoryItem): bool => $inventoryItem instanceof Usable,
15
        );
16
    }
17
18
    /**
19
     * @note This method mutates state of the collection
20
     */
21
    public function add(InventoryItem $item): self
22
    {
23
        $this->items[] = $item;
24
25
        return $this;
26
    }
27
28
    /**
29
     * @note This method mutates state of the collection
30
     */
31
    public function addMany(InventoryItem ...$items): self
32
    {
33
        $this->items = array_merge($this->items, $items);
34
35
        return $this;
36
    }
37
38
    /**
39
     * @note This method mutates state of the collection
40
     */
41 1
    public function remove(InventoryItem $item): self
42
    {
43 1
        $this->items = $this->filter(
44 1
            static fn(InventoryItem $inventoryItem): bool => $inventoryItem !== $item,
45 1
        )->getItems();
46
47 1
        return $this;
48
    }
49
50 6
    protected function getType(): string
51
    {
52 6
        return InventoryItem::class;
53
    }
54
}
55