/** * @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(); }
/** * @param boolean $addedNewline * @param string $tab * @param $token * @param $queryValue * * @return mixed */ protected function formatTokenTypeReservedTopLevel($addedNewline, $tab, $token, $queryValue) { $this->indentation->setIncreaseSpecialIndent(true)->decreaseSpecialIndentIfCurrentIndentTypeIsSpecial(); $this->newLine->writeNewLineBecauseOfTopLevelReservedWord($addedNewline, $tab); if (WhiteSpace::tokenHasExtraWhiteSpaces($token)) { $queryValue = preg_replace('/\\s+/', ' ', $queryValue); } Token::tokenHasLimitClause($token, $this->parentheses, $this); return $queryValue; }
/** * 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; }
/** * @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 . ' '); }