Lines 100.00% 5 / 5
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 4 / 4 100.00% 1 / 1 3
 price 100.00% 1 / 1 100.00% 1 / 1 1
14final readonly class CurrencyShop extends Shop
15{
16    /**
17     * @param Inventory<Item> $inventory
18     * @param array<positive-int, ItemPrice> $prices
19     *
20     * @throws InvalidArgumentException
21     */
22    public function __construct(
23        ShopId $id,
24        ShopName $name,
25        public Inventory $inventory,
26        private array $prices,
27    ) {
28        parent::__construct($id, $name);
29
30        foreach ($inventory as $item) {
31            if (!array_key_exists($item->id->value, $prices)) {
32                throw new InvalidArgumentException("{$item->name} is sold without a price.");
33            }
34        }
35    }
36
37    /** @return Option\Option<ItemPrice> */
38    public function price(ItemId $id): Option\Option
39    {
40        return Option\from_nullable($this->prices[$id->value] ?? null);
41    }
42}