Passed
Push — master ( df7727...a665f8 )
by Paweł
03:01
created

Inventory::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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
    public function filterUsable(): self
12
    {
13
        return $this->filter(
14
            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
    public function remove(InventoryItem $item): self
42
    {
43
        $this->items = $this->filter(
44
            static fn(InventoryItem $inventoryItem): bool => $inventoryItem !== $item,
45
        )->getItems();
46
47
        return $this;
48
    }
49
50 1
    protected function getType(): string
51
    {
52 1
        return InventoryItem::class;
53
    }
54
}
55