src/Query.php
protected function _render_case()
    {
        if (!isset($this->args['case_when'])) {
            return;
        }

        $ret = '';

        // operand
        if ($short_form = isset($this->args['case_operand'])) {
            $ret .= ' '.$this->_consume($this->args['case_operand'], 'soft-escape');
        }

        // when, then
        foreach ($this->args['case_when'] as $row) {
            if (!array_key_exists(0, $row) || !array_key_exists(1, $row)) {
                throw new Exception([
                    'Incorrect use of "when" method parameters',
                    'row'  => $row,
                ]);
            }

            $ret .= ' when ';
            if ($short_form) {
                // short-form
                if (is_array($row[0])) {
                    throw new Exception([
                        'When using short form CASE statement, then you should not set array as when() method 1st parameter',
                        'when'  => $row[0],
                    ]);
                }
                $ret .= $this->_consume($row[0], 'param');
            } else {
                $ret .= $this->__render_condition($row[0]);
            }

            // then
            $ret .= ' then '.$this->_consume($row[1], 'param');
        }

        // else
        if (array_key_exists('case_else', $this->args)) {
            $ret .= ' else '.$this->_consume($this->args['case_else'], 'param');
        }

        return ' case'.$ret.' end';
    }
protected function _render_case()
    {
        if (!isset($this->args['case_when'])) {
            return;
        }

        $ret = '';

        // operand
        if ($short_form = isset($this->args['case_operand'])) {
            $ret .= ' '.$this->_consume($this->args['case_operand'], 'soft-escape');
        }

        // when, then
        foreach ($this->args['case_when'] as $row) {
            if (!array_key_exists(0, $row) || !array_key_exists(1, $row)) {
                throw new Exception([
                    'Incorrect use of "when" method parameters',
                    'row'  => $row,
                ]);
            }

            $ret .= ' when ';
            if ($short_form) {
                // short-form
                if (is_array($row[0])) {
                    throw new Exception([
                        'When using short form CASE statement, then you should not set array as when() method 1st parameter',
                        'when'  => $row[0],
                    ]);
                }
                $ret .= $this->_consume($row[0], 'param');
            } else {
                $ret .= $this->__render_condition($row[0]);
            }

            // then
            $ret .= ' then '.$this->_consume($row[1], 'param');
        }

        // else
        if (array_key_exists('case_else', $this->args)) {
            $ret .= ' else '.$this->_consume($this->args['case_else'], 'param');
        }

        return ' case'.$ret.' end';
    }
Renders [case].

@return string rendered SQL chunk