_condition[] = 'CASE ' . $column; } /** * @param string|int $condition * @param string $then * @return $this * @throws */ public function when(string|int $condition, string $then): static { $this->_condition[] = sprintf('WHEN %s THEN %s', $condition, $then); return $this; } /** * @param string $alias */ public function else(string $alias): void { $this->else = $alias; } /** * @return string */ #[Pure] public function end(): string { if (empty($this->_condition)) { return ''; } $prefix = implode(' ', $this->_condition); if (!empty($this->else)) { $prefix .= ' ELSE ' . $this->else; } return '(' . $prefix . ' END)'; } }