Lines 95.00% 19 / 20
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% 12 / 12 100.00% 1 / 1 6
 summary 0.00% 0 / 1 0.00% 0 / 1 2
 [Lorekeeper\Server\Event\NamedAfterClass] name 100.00% 6 / 6 100.00% 1 / 1 1
19final readonly class RoomJoinedEvent implements Event
20{
21    use NamedAfterClass;
22
23    /** @param list<PlayerName> $players */
24    public function __construct(
25        public array $players,
26    ) {}
27
28    /** @return Option\Option<static> */
29    #[Override]
30    public static function from(Message $message): Option\Option
31    {
32        if (!$message instanceof XmlMessage) {
33            return Option\none();
34        }
35
36        $body = $message->dom->getElementsByTagName('body')->item(0);
37        if (!$body instanceof DOMElement || $body->getAttribute('action') !== 'joinOK') {
38            return Option\none();
39        }
40
41        $players = [];
42        foreach ($body->getElementsByTagName('u') as $user) {
43            try {
44                $name = Type\non_empty_string()->coerce($user->getElementsByTagName('n')->item(0)?->textContent);
45            } catch (CoercionException $exception) {
46                throw new MalformedEventException(static::class, 'a player name is missing or invalid', $exception);
47            }
48
49            $players[] = new PlayerName($name);
50        }
51
52        return Option\some(new static($players));
53    }
54
55    #[Override]
56    public function summary(): string
57    {
58        return 'Joined a room with ' . count($this->players) . ' players';
59    }
60}

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}