/**
  * @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();
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 /**
  * Returns a SQL string in a readable human-friendly format.
  *
  * @param QueryInterface $query
  *
  * @return string
  */
 public function writeFormatted(QueryInterface $query)
 {
     if (null === $this->sqlFormatter) {
         $this->sqlFormatter = (new \ReflectionClass($this->sqlFormatterClass))->newInstance();
     }
     return $this->sqlFormatter->format($this->write($query));
 }
 /**
  * Commas start a new line unless they are found within inline parentheses or SQL 'LIMIT' clause.
  * If the previous TOKEN_VALUE is 'LIMIT', undo new line.
  */
 public function writeNewLineBecauseOfComma()
 {
     $this->newline = true;
     if (true === $this->formatter->getClauseLimit()) {
         $this->newline = false;
         $this->formatter->setClauseLimit(false);
     }
 }
Example #5
0
 /**
  * @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 . ' ');
 }
 /**
  * @test
  * @dataProvider sqlQueryDataProvider
  *
  * @param $notIndented
  * @param $indented
  */
 public function itShouldReformatNoIndentQueriesToIndentedVersions($notIndented, $indented)
 {
     $formatter = new Formatter();
     $result = $formatter->format($notIndented);
     $this->assertSame($indented, $result);
 }
Example #7
0
 /**
  * @param string $token
  * @param Parentheses $parentheses
  * @param Formatter $formatter
  */
 public static function tokenHasLimitClause($token, Parentheses $parentheses, Formatter $formatter)
 {
     if ('LIMIT' === $token[Tokenizer::TOKEN_VALUE] && false === $parentheses->getInlineParentheses()) {
         $formatter->setClauseLimit(true);
     }
 }