*/ public array $sent = []; public bool $closed = false; public function __construct(private string $id) {} public function id(): string { return $this->id; } public function send(string $message): void { $this->sent[] = $message; } public function close(): void { $this->closed = true; } /** @return array> */ public function jsonMessages(): array { return array_map(fn ($s) => json_decode($s, true) ?? [], $this->sent); } /** @return array */ public function lastJson(): array { $last = end($this->sent); return $last === false ? [] : (json_decode($last, true) ?? []); } }