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

Inventory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 44
ccs 10
cts 16
cp 0.625
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A add() 0 5 1
A addMany() 0 5 1
A remove() 0 7 1
A filterUsable() 0 4 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