Lines 100.00% 14 / 14
Methods 100.00% 4 / 4
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 from 100.00% 6 / 6 100.00% 1 / 1 4
 summary 100.00% 1 / 1 100.00% 1 / 1 1
 [Lorekeeper\Server\Event\NamedAfterClass] name 100.00% 6 / 6 100.00% 1 / 1 1
21final readonly class MonsterRespawnedEvent implements Event
22{
23    use NamedAfterClass;
24
25    public function __construct(
26        public MonsterSpawnId $id,
27    ) {}
28
29    /** @return Option\Option<static> */
30    #[Override]
31    public static function from(Message $message): Option\Option
32    {
33        if (!$message instanceof DelimitedMessage || ($message->data[1] ?? null) !== 'respawnMon') {
34            return Option\none();
35        }
36
37        try {
38            $id = Type\positive_int()->coerce($message->data[3] ?? null);
39        } catch (CoercionException $exception) {
40            throw new MalformedEventException(static::class, 'monster id is missing or invalid', $exception);
41        }
42
43        return Option\some(new static(new MonsterSpawnId($id)));
44    }
45
46    #[Override]
47    public function summary(): string
48    {
49        return "Monster {$this->id->value} came back";
50    }
51}

From Lorekeeper\Server\Event\NamedAfterClass

7trait NamedAfterClass
8{
9    public function name(): string
10    {
11        $class = static::class;
12
13        return (string) preg_replace(
14            '/Event$/',
15            replacement: '',
16            subject: substr($class, (int) strrpos($class, needle: '\\') + 1),
17        );
18    }
19}