Lines
100.00%
20 / 20
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| from | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 5 | ||
| summary | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 2 | ||
| 18 | final readonly class ItemsIncreasedEvent extends InventoryUpdatedEvent | |
| 19 | { | |
| 20 | /** @param non-empty-list<ItemIncrease> $items */ | |
| 21 | public function __construct( | |
| 22 | public array $items, | |
| 23 | ) {} | |
| 24 | ||
| 25 | /** @return Option\Option<static> */ | |
| 26 | #[Override] | |
| 27 | public static function from(Message $message): Option\Option | |
| 28 | { | |
| 29 | $items = []; | |
| 30 | foreach (ItemArrivals::of($message, static::class) ?? [] as [$kind, $entry]) { | |
| 31 | $held = $entry['iQtyNow'] ?? null; | |
| 32 | if ($kind !== ItemArrival::ItemIncreased || $held === null) { | |
| 33 | continue; | |
| 34 | } | |
| 35 | ||
| 36 | $items[] = new ItemIncrease( | |
| 37 | new ItemId($entry['ItemID']), | |
| 38 | new Quantity($entry['iQty']), | |
| 39 | new Quantity($held), | |
| 40 | ); | |
| 41 | } | |
| 42 | ||
| 43 | return $items === [] ? Option\none() : Option\some(new static($items)); | |
| 44 | } | |
| 45 | ||
| 46 | #[Override] | |
| 47 | public function summary(): string | |
| 48 | { | |
| 49 | return 'Got ' | |
| 50 | . implode(', ', array_map( | |
| 51 | static fn(ItemIncrease $added): string => ( | |
| 52 | "{$added->quantity->value} more of item {$added->item->value}" | |
| 53 | . ($added->held === null ? '' : ", {$added->held->value} held now") | |
| 54 | ), | |
| 55 | $this->items, | |
| 56 | )); | |
| 57 | } | |
| 58 | } |