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

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}