Lines
100.00%
24 / 24
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| summary | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| read | 100.00% | 14 / 14 | 100.00% | 1 / 1 | 2 | ||
| room | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 4 | ||
| [Lorekeeper\Server\Event\Map\MapArrivalEvent] from | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | ||
| 16 | final readonly class MovedToMapEvent extends MapArrivalEvent | |
| 17 | { | |
| 18 | public function __construct( | |
| 19 | public AreaId $areaId, | |
| 20 | public RoomId $roomId, | |
| 21 | public MapName $map, | |
| 22 | public Gamefile $file, | |
| 23 | ) {} | |
| 24 | ||
| 25 | #[Override] | |
| 26 | public function summary(): string | |
| 27 | { | |
| 28 | return "{$this->map->value} (room {$this->roomId->value})"; | |
| 29 | } | |
| 30 | ||
| 31 | #[Override] | |
| 32 | protected static function read(array $data): static | |
| 33 | { | |
| 34 | try { | |
| 35 | $data = Type\shape([ | |
| 36 | 'areaId' => Type\positive_int(), | |
| 37 | 'areaName' => Type\non_empty_string(), | |
| 38 | 'strMapName' => Type\non_empty_string(), | |
| 39 | 'strMapFileName' => Type\non_empty_string(), | |
| 40 | ], allowUnknownFields: true)->coerce($data); | |
| 41 | } catch (CoercionException $exception) { | |
| 42 | throw new MalformedEventException(static::class, 'map data is missing or invalid', $exception); | |
| 43 | } | |
| 44 | ||
| 45 | return new static( | |
| 46 | new AreaId($data['areaId']), | |
| 47 | self::room($data['areaName']), | |
| 48 | new MapName($data['strMapName']), | |
| 49 | new Gamefile($data['strMapFileName']), | |
| 50 | ); | |
| 51 | } | |
| 52 | ||
| 53 | /** @throws MalformedEventException */ | |
| 54 | private static function room(string $areaName): RoomId | |
| 55 | { | |
| 56 | $separator = strrpos($areaName, needle: '-'); | |
| 57 | $room = $separator === false ? '' : substr($areaName, $separator + 1); | |
| 58 | ||
| 59 | if (!ctype_digit($room) || (int) $room < 1) { | |
| 60 | throw new MalformedEventException(static::class, "area name '{$areaName}' has no room number"); | |
| 61 | } | |
| 62 | ||
| 63 | return new RoomId((int) $room); | |
| 64 | } | |
| 65 | } |
Inherited from Lorekeeper\Server\Event\Map\MapArrivalEvent
| 28 | final public static function from(Message $message): Option\Option | |
| 29 | { | |
| 30 | if (!$message instanceof JsonMessage || ($message->data['cmd'] ?? null) !== 'moveToArea') { | |
| 31 | return Option\none(); | |
| 32 | } | |
| 33 | ||
| 34 | return Option\some(static::read($message->data)); | |
| 35 | } |