Lines 90.00% 18 / 20
Methods 50.00% 1 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 read n/a 0 / 0 n/a 0 / 0 0
 from 85.71% 12 / 14 0.00% 0 / 1 4.05
 [Lorekeeper\Server\Event\NamedAfterClass] name 100.00% 6 / 6 100.00% 1 / 1 1
17abstract readonly class CombatRoundEvent implements Event
18{
19    use NamedAfterClass;
20
21    /**
22     * @param array<positive-int, array{intHP?: non-negative-int, intMP?: non-negative-int, intState?: int<0, 2>}> $monsters
23     * @param array<non-empty-string, array{intHP?: non-negative-int, intMP?: non-negative-int, intState?: int<0, 2>}> $players
24     *
25     * @return Option\Option<static>
26     */
27    abstract protected static function read(array $monsters, array $players): Option\Option;
28
29    /** @return Option\Option<static> */
30    #[Override]
31    final public static function from(Message $message): Option\Option
32    {
33        if (!$message instanceof JsonMessage || ($message->data['cmd'] ?? null) !== 'ct') {
34            return Option\none();
35        }
36
37        $status = Type\shape([
38            'intHP' => Type\optional(Type\uint()),
39            'intMP' => Type\optional(Type\uint()),
40            'intState' => Type\optional(Type\int_range(min: 0, max: 2)),
41        ], allowUnknownFields: true);
42
43        try {
44            $round = Type\shape([
45                'm' => Type\optional(Type\dict(Type\positive_int(), $status)),
46                'p' => Type\optional(Type\dict(Type\non_empty_string(), $status)),
47            ], allowUnknownFields: true)->coerce($message->data);
48        } catch (CoercionException $exception) {
49            throw new MalformedEventException(static::class, 'combat round is invalid', $exception);
50        }
51
52        return static::read($round['m'] ?? [], $round['p'] ?? []);
53    }
54}

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}