Lines 100.00% 21 / 21
Methods 100.00% 7 / 7
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 wear 100.00% 2 / 2 100.00% 1 / 1 1
 worn 100.00% 1 / 1 100.00% 1 / 1 1
 wears 100.00% 1 / 1 100.00% 1 / 1 1
 [Lorekeeper\Core\Player\Hero\Inventory\HeroSlots] __construct 100.00% 1 / 1 100.00% 1 / 1 1
 [Lorekeeper\Core\Player\Hero\Inventory\HeroSlots] put 100.00% 3 / 3 100.00% 1 / 1 2
 [Lorekeeper\Core\Player\Hero\Inventory\HeroSlots] at 100.00% 5 / 5 100.00% 1 / 1 2
 [Lorekeeper\Core\Player\Hero\Inventory\HeroSlots] holds 100.00% 8 / 8 100.00% 1 / 1 2
13final class HeroCostume extends HeroSlots
14{
15    /**
16     * @return $this
17     *
18     * @throws InvalidArgumentException
19     */
20    public function wear(Equipment $item): static
21    {
22        $this->put($item);
23
24        return $this;
25    }
26
27    /** @return Option\Option<Equipment> */
28    public function worn(EquipmentSlot $slot): Option\Option
29    {
30        return $this->at($slot);
31    }
32
33    public function wears(ItemId $id): bool
34    {
35        return $this->holds($id);
36    }
37}

Inherited from Lorekeeper\Core\Player\Hero\Inventory\HeroSlots

20    final public function __construct(
21        private readonly Stock $kept,
22    ) {}
25    protected function put(Equipment $item): void
26    {
27        if ($this->kept->find($item->id)->isNone()) {
28            throw new InvalidArgumentException("Item {$item->id} is not kept, so it cannot be put on.");
29        }
30
31        $this->slots[$item->slot()->value] = $item->id;
32    }
35    protected function at(EquipmentSlot $slot): Option\Option
36    {
37        return Option\from_nullable($this->slots[$slot->value] ?? null)
38            ->andThen(fn(ItemId $id): Option\Option => $this->kept->find($id))
39            ->andThen(static fn(Item $item): Option\Option => $item instanceof Equipment
40                ? Option\some($item)
41                : Option\none());
42    }
44    protected function holds(ItemId $id): bool
45    {
46        return $this->kept
47            ->find($id)
48            ->andThen(static fn(Item $item): Option\Option => $item instanceof Equipment
49                ? Option\some($item)
50                : Option\none())
51            ->isSomeAnd(fn(Equipment $item): bool => $this->at($item->slot())->isSomeAnd(
52                static fn(Equipment $on): bool => $on === $item,
53            ));
54    }