isValid($val)) { throw new InvalidArgumentException("Valeur du rĂ´le invalide"); } $this->value = $val; } public static function player(): MemberRole { return new MemberRole(MemberRole::ROLE_PLAYER); } public static function coach(): MemberRole { return new MemberRole(MemberRole::ROLE_COACH); } public function name(): string { switch ($this->value) { case self::ROLE_COACH: return "COACH"; case self::ROLE_PLAYER: return "PLAYER"; } die("unreachable"); } public static function fromName(string $name): ?MemberRole { switch ($name) { case "COACH": return MemberRole::coach(); case "PLAYER": return MemberRole::player(); default: return null; } } private function isValid(int $val): bool { return ($val <= self::MAX and $val >= self::MIN); } public function isPlayer(): bool { return ($this->value == self::ROLE_PLAYER); } public function isCoach(): bool { return ($this->value == self::ROLE_COACH); } }