Lines
100.00%
23 / 23
Methods
100.00%
9 / 9
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| key | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lorekeeper\Core\Support\Collection] __construct | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| [Lorekeeper\Core\Support\Collection] add | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | ||
| [Lorekeeper\Core\Support\Collection] remove | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 2 | ||
| [Lorekeeper\Core\Support\Collection] has | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lorekeeper\Core\Support\Collection] find | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lorekeeper\Core\Support\Collection] filter | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | ||
| [Lorekeeper\Core\Support\Collection] getIterator | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| [Lorekeeper\Core\Support\Collection] count | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 14 | class Inventory extends Collection | |
| 15 | { | |
| 16 | /** @param T $item */ | |
| 17 | final protected static function key(mixed $item): ItemId | |
| 18 | { | |
| 19 | return $item->id; | |
| 20 | } | |
| 21 | } |
Inherited from Lorekeeper\Core\Support\Collection
| 31 | final public function __construct(array $items) | |
| 32 | { | |
| 33 | $this->items = new MutableMap([]); | |
| 34 | foreach ($items as $item) { | |
| 35 | $this->add($item); | |
| 36 | } | |
| 37 | } |
| 53 | public function add(mixed $item): static | |
| 54 | { | |
| 55 | $key = static::key($item)->value; | |
| 56 | if ($this->items->contains($key)) { | |
| 57 | throw new InvalidArgumentException("{$key} is in the collection more than once."); | |
| 58 | } | |
| 59 | ||
| 60 | $this->items->add($key, $item); | |
| 61 | ||
| 62 | return $this; | |
| 63 | } |
| 72 | public function remove(PositiveInteger|NonEmptyString $key): static | |
| 73 | { | |
| 74 | if (!$this->items->contains($key->value)) { | |
| 75 | throw new InvalidArgumentException("{$key} is not in the collection."); | |
| 76 | } | |
| 77 | ||
| 78 | $this->items->remove($key->value); | |
| 79 | ||
| 80 | return $this; | |
| 81 | } |
| 84 | public function has(mixed $item): bool | |
| 85 | { | |
| 86 | return $this->items->contains(static::key($item)->value); | |
| 87 | } |
| 94 | public function find(PositiveInteger|NonEmptyString $key): Option\Option | |
| 95 | { | |
| 96 | return Option\from_nullable($this->items->get($key->value)); | |
| 97 | } |
| 104 | public function filter(Closure $fn): static | |
| 105 | { | |
| 106 | /** @var static<K, T> */ | |
| 107 | return new static( | |
| 108 | $this->items | |
| 109 | ->filter($fn) | |
| 110 | ->values() | |
| 111 | ->toArray(), | |
| 112 | ); | |
| 113 | } |
| 116 | public function getIterator(): Iterator | |
| 117 | { | |
| 118 | return $this->items->getIterator(); | |
| 119 | } |
| 121 | public function count(): int | |
| 122 | { | |
| 123 | return $this->items->count(); | |
| 124 | } |