/** * @param $token * @param string $tab * @param $queryValue * * @return string */ public function writeCommentBlock($token, $tab, $queryValue) { if ($token[Tokenizer::TOKEN_TYPE] === Tokenizer::TOKEN_TYPE_BLOCK_COMMENT) { $indent = str_repeat($tab, $this->indentation->getIndentLvl()); $this->formatter->appendToFormattedSql("\n" . $indent); $queryValue = str_replace("\n", "\n" . $indent, $queryValue); } $this->formatter->appendToFormattedSql($queryValue); $this->newLine->setNewline(true); return $this->formatter->getFormattedSql(); }
/** * Add a newline before the top level reserved word if necessary and indent. * * @param boolean $addedNewline * @param string $tab */ public function writeNewLineBecauseOfTopLevelReservedWord($addedNewline, $tab) { if (false === $addedNewline) { $this->formatter->appendToFormattedSql("\n"); } else { $this->formatter->setFormattedSql(rtrim($this->formatter->getFormattedSql(), $tab)); } $this->formatter->appendToFormattedSql(str_repeat($tab, $this->indentation->getIndentLvl())); $this->newline = true; }
/** * Closing parentheses decrease the block indent level. * * @param Formatter $formatter * * @return $this */ public function decreaseIndentLevelUntilIndentTypeIsSpecial(Formatter $formatter) { $formatter->setFormattedSql(\rtrim($formatter->getFormattedSql(), ' ')); --$this->indentLvl; while ($j = \array_shift($this->indentTypes)) { if ('special' !== $j) { break; } --$this->indentLvl; } return $this; }
/** * @param string $tab * @param $queryValue */ public function writeInlineParenthesesBlock($tab, $queryValue) { $this->formatter->setFormattedSql(\rtrim($this->formatter->getFormattedSql(), ' ')); if ($this->indentation->getInlineIndented()) { $indentTypes = $this->indentation->getIndentTypes(); \array_shift($indentTypes); $this->indentation->setIndentTypes($indentTypes); $this->indentation->setIndentLvl($this->indentation->getIndentLvl() - 1); $this->formatter->appendToFormattedSql("\n" . str_repeat($tab, $this->indentation->getIndentLvl())); } $this->inlineParentheses = false; $this->formatter->appendToFormattedSql($queryValue . ' '); }