Lines 100.00% 16 / 16
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% 8 / 8 100.00% 1 / 1 5
 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 LoginSucceededEvent implements Event
22{
23    use NamedAfterClass;
24
25    public function __construct(
26        public PlayerSpawnId $spawnId,
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) !== 'loginResponse') {
34            return Option\none();
35        }
36
37        if (($message->data[3] ?? null) !== 'true') {
38            return Option\none();
39        }
40
41        try {
42            $spawnId = Type\positive_int()->coerce($message->data[4] ?? null);
43        } catch (CoercionException $exception) {
44            throw new MalformedEventException(static::class, 'spawn id is missing or invalid', $exception);
45        }
46
47        return Option\some(new static(new PlayerSpawnId($spawnId)));
48    }
49
50    #[Override]
51    public function summary(): string
52    {
53        return "Logged in as spawn {$this->spawnId->value}";
54    }
55}

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}