Lines 100.00% 5 / 5
Functions and Methods 100.00% 2 / 2
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
MergeShop 100.00% 5 / 5 100.00% 2 / 2 4 100.00% 1 / 1
 __construct 100.00% 4 / 4 100.00% 1 / 1 3
 costs 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Lorekeeper\Core\World\Shop;
6
7use InvalidArgumentException;
8use Lorekeeper\Core\Item\Inventory;
9use Lorekeeper\Core\Item\Item;
10use Lorekeeper\Core\Item\ItemId;
11use Psl\Option;
12
13final readonly class MergeShop extends Shop
14{
15    /**
16     * @param Inventory<Item> $inventory
17     * @param array<positive-int, list<MergeCost>> $costs
18     *
19     * @throws InvalidArgumentException
20     */
21    public function __construct(
22        ShopId $id,
23        ShopName $name,
24        public Inventory $inventory,
25        private array $costs,
26    ) {
27        parent::__construct($id, $name);
28
29        foreach ($inventory as $item) {
30            if (($costs[$item->id->value] ?? []) === []) {
31                throw new InvalidArgumentException("Merging {$item->name} costs nothing.");
32            }
33        }
34    }
35
36    /** @return Option\Option<list<MergeCost>> */
37    public function costs(ItemId $id): Option\Option
38    {
39        return Option\from_nullable($this->costs[$id->value] ?? null);
40    }
41}