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
3declare(strict_types=1);
4
5namespace Lorekeeper\Server\Event\Map;
6
7use Lorekeeper\Core\World\Map\MapName;
8use Lorekeeper\Server\Event\Event;
9use Lorekeeper\Server\Event\NamedAfterClass;
10use Lorekeeper\Server\Event\Notice;
11use Lorekeeper\Server\Message\Message;
12use Override;
13use Psl\Option;
14
15final 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}