Lines
100.00%
8 / 8
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MapNotAvailableEvent | 100.00% | 8 / 8 | 100.00% | 3 / 3 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| from | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 2 | |||||
| summary | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Lorekeeper\Server\Event\Map; | |
| 6 | ||
| 7 | use Lorekeeper\Core\World\Map\MapName; | |
| 8 | use Lorekeeper\Server\Event\Event; | |
| 9 | use Lorekeeper\Server\Event\NamedAfterClass; | |
| 10 | use Lorekeeper\Server\Event\Notice; | |
| 11 | use Lorekeeper\Server\Message\Message; | |
| 12 | use Override; | |
| 13 | use Psl\Option; | |
| 14 | ||
| 15 | /** | |
| 16 | * The server refused to move our player because the map is not available. | |
| 17 | */ | |
| 18 | final readonly class MapNotAvailableEvent implements Event | |
| 19 | { | |
| 20 | use NamedAfterClass; | |
| 21 | ||
| 22 | public function __construct( | |
| 23 | public MapName $mapName, | |
| 24 | ) {} | |
| 25 | ||
| 26 | /** @return Option\Option<static> */ | |
| 27 | #[Override] | |
| 28 | public static function from(Message $message): Option\Option | |
| 29 | { | |
| 30 | return Notice::text($message, 'warning')->andThen(static function (string $text): Option\Option { | |
| 31 | $match = []; | |
| 32 | ||
| 33 | if (preg_match('/^(\S+) is not available/i', $text, $match) !== 1) { | |
| 34 | return Option\none(); | |
| 35 | } | |
| 36 | ||
| 37 | return Option\some($match[1]); | |
| 38 | })->map(static fn(string $name): static => new static(new MapName($name))); | |
| 39 | } | |
| 40 | ||
| 41 | #[Override] | |
| 42 | public function summary(): string | |
| 43 | { | |
| 44 | return "{$this->mapName->value} is not available"; | |
| 45 | } | |
| 46 | } |