<?phpnamespace App\Chat;/** * A member as the server describes him: id "n:n:n:origin", nickname, age, sex (0 woman, 1 man, 2 other: the applet * drew 0 pink and 1 blue), city, admin (1, 2 moderators), where (his room), state (26 flags: 2 no private, 64 busy). */final class Member{ public function __construct( public readonly string $id, public readonly string $nickname, public readonly int $age, public readonly int $sex, public readonly string $city, public readonly int $admin = 0, public readonly string $where = '', public readonly int $state = 0, ) { } public function origin(): string { $parts = explode(':', $this->id); return (string)end($parts); } public function isAdmin(): bool { return $this->admin === 1 || $this->admin === 2; } /** "Toto, 25 ans, F, Lyon" — the profile line of the lists' tooltip. */ public function profile(): string { $bits = []; if ($this->age > 0) { $bits[] = $this->age . ' ' . \JumPHP\Util\Lang::t('y.o.'); } if ($this->isAdmin()) { $bits[] = \JumPHP\Util\Lang::t('moderator'); } elseif ($this->sex === 0 || $this->sex === 1) { $bits[] = $this->sex === 0 ? \JumPHP\Util\Lang::t('woman') : \JumPHP\Util\Lang::t('man'); } if ($this->city !== '') { $bits[] = $this->city; } return $this->nickname . ($bits === [] ? '' : ' — ' . implode(', ', $bits)); } public function with(?string $nickname = null): self { return new self($this->id, $nickname ?? $this->nickname, $this->age, $this->sex, $this->city, $this->admin, $this->where, $this->state); }}