Lines 100.00% 25 / 25
Methods 100.00% 4 / 4
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 read 100.00% 6 / 6 100.00% 1 / 1 4
 summary 100.00% 4 / 4 100.00% 1 / 1 1
 [Lorekeeper\Server\Event\Combat\CombatRoundEvent] from 100.00% 14 / 14 100.00% 1 / 1 4
15final readonly class PlayersHealthChangedEvent extends CombatRoundEvent
16{
17    /** @param non-empty-list<PlayerHealth> $players */
18    public function __construct(
19        public array $players,
20    ) {}
21
22    #[Override]
23    protected static function read(array $monsters, array $players): Option\Option
24    {
25        $changed = [];
26        foreach ($players as $name => $player) {
27            if (!array_key_exists('intHP', $player)) {
28                continue;
29            }
30
31            $changed[] = new PlayerHealth(new PlayerName($name), new Health($player['intHP']));
32        }
33
34        return $changed === [] ? Option\none() : Option\some(new static($changed));
35    }
36
37    #[Override]
38    public function summary(): string
39    {
40        return implode(', ', array_map(
41            static fn(PlayerHealth $player): string => "{$player->player->value} has {$player->health->value} health",
42            $this->players,
43        ));
44    }
45}

Inherited from Lorekeeper\Server\Event\Combat\CombatRoundEvent

34    final public static function from(Message $message): Option\Option
35    {
36        if (!$message instanceof JsonMessage || ($message->data['cmd'] ?? null) !== 'ct') {
37            return Option\none();
38        }
39
40        $status = Type\shape([
41            'intHP' => Type\optional(Type\uint()),
42            'intMP' => Type\optional(Type\uint()),
43            'intState' => Type\optional(Type\int_range(min: 0, max: 2)),
44        ], allowUnknownFields: true);
45
46        try {
47            $round = Type\shape([
48                'm' => Type\optional(Type\dict(Type\positive_int(), $status)),
49                'p' => Type\optional(Type\dict(Type\non_empty_string(), $status)),
50            ], allowUnknownFields: true)->coerce($message->data);
51        } catch (CoercionException $exception) {
52            throw new MalformedEventException(static::class, 'combat round is invalid', $exception);
53        }
54
55        return static::read($round['m'] ?? [], $round['p'] ?? []);
56    }