for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace AardsGerds\Game\Inventory;
use AardsGerds\Game\Shared\Collection;
final class Inventory extends Collection
{
public function filterUsable(): self
return $this->filter(
static fn(InventoryItem $inventoryItem): bool => $inventoryItem instanceof Usable,
);
}
/**
* @note This method mutates state of the collection
*/
public function add(InventoryItem $item): self
$this->items[] = $item;
return $this;
public function addMany(InventoryItem ...$items): self
$this->items = array_merge($this->items, $items);
public function remove(InventoryItem $item): self
$this->items = $this->filter(
static fn(InventoryItem $inventoryItem): bool => $inventoryItem !== $item,
)->getItems();
protected function getType(): string
return InventoryItem::class;