Lines
87.50%
7 / 8
Functions and Methods
66.66%
2 / 3
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MapNotAvailableEvent | 87.50% | 7 / 8 | 66.66% | 2 / 3 | 4.03 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| from | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 2 | |||||
| summary | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 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 | final readonly class MapNotAvailableEvent implements Event | |
| 16 | { | |
| 17 | use NamedAfterClass; | |
| 18 | ||
| 19 | public function __construct( | |
| 20 | public MapName $mapName, | |
| 21 | ) {} | |
| 22 | ||
| 23 | /** @return Option\Option<static> */ | |
| 24 | #[Override] | |
| 25 | public static function from(Message $message): Option\Option | |
| 26 | { | |
| 27 | return Notice::text($message, 'warning')->andThen(static function (string $text): Option\Option { | |
| 28 | $match = []; | |
| 29 | ||
| 30 | if (preg_match('/^(\S+) is not available/i', $text, $match) !== 1) { | |
| 31 | return Option\none(); | |
| 32 | } | |
| 33 | ||
| 34 | return Option\some($match[1]); | |
| 35 | })->map(static fn(string $name): static => new static(new MapName($name))); | |
| 36 | } | |
| 37 | ||
| 38 | #[Override] | |
| 39 | public function summary(): string | |
| 40 | { | |
| 41 | return "{$this->mapName->value} is not available"; | |
| 42 | } | |
| 43 | } |