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 2
 [Lorekeeper\Server\Event\NamedAfterClass] name 100.00% 6 / 6 100.00% 1 / 1 1
17final readonly class LoginFailedEvent implements Event
18{
19    use NamedAfterClass;
20
21    public function __construct(
22        public string $reason = '',
23    ) {}
24
25    /** @return Option\Option<static> */
26    #[Override]
27    public static function from(Message $message): Option\Option
28    {
29        if (!$message instanceof DelimitedMessage || ($message->data[1] ?? null) !== 'loginResponse') {
30            return Option\none();
31        }
32
33        if (!in_array($message->data[3] ?? null, ['0', 'false'], strict: true)) {
34            return Option\none();
35        }
36
37        $said = array_slice($message->data, offset: 5);
38
39        return Option\some(new static(trim((string) end($said))));
40    }
41
42    #[Override]
43    public function summary(): string
44    {
45        return $this->reason === '' ? 'Login refused' : "Login refused: {$this->reason}";
46    }
47}

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}