| Total Complexity | 5 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | final class Inventory extends Collection |
||
| 10 | { |
||
| 11 | 2 | public function filterConsumable(): self |
|
| 12 | { |
||
| 13 | 2 | return $this->filter( |
|
| 14 | 2 | static fn(InventoryItem $inventoryItem): bool => $inventoryItem instanceof Consumable, |
|
| 15 | ); |
||
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @note This method mutates state of the collection |
||
| 20 | */ |
||
| 21 | 1 | public function add(InventoryItem $item): self |
|
| 22 | { |
||
| 23 | 1 | $this->items[] = $item; |
|
| 24 | |||
| 25 | 1 | return $this; |
|
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @note This method mutates state of the collection |
||
| 30 | */ |
||
| 31 | 1 | public function addMany(InventoryItem ...$items): self |
|
| 32 | { |
||
| 33 | 1 | $this->items = array_merge($this->items, $items); |
|
| 34 | |||
| 35 | 1 | return $this; |
|
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @note This method mutates state of the collection |
||
| 40 | */ |
||
| 41 | 2 | public function remove(InventoryItem $item): self |
|
| 42 | { |
||
| 43 | 2 | $this->items = $this->filter( |
|
| 44 | 2 | static fn(InventoryItem $inventoryItem): bool => $inventoryItem !== $item, |
|
| 45 | 2 | )->getItems(); |
|
| 46 | |||
| 47 | 2 | return $this; |
|
| 48 | } |
||
| 49 | |||
| 50 | 10 | protected function getType(): string |
|
| 53 | } |
||
| 54 | } |
||
| 55 |