Skip to content

Commit

Permalink
Simplify WithStatement::build()
Browse files Browse the repository at this point in the history
Signed-off-by: Kamil Tekiela <[email protected]>
  • Loading branch information
kamil-tekiela committed Jan 17, 2025
1 parent 8db6524 commit 562773c
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/Statements/WithStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PhpMyAdmin\SqlParser\Translator;

use function array_slice;
use function implode;
use function preg_match;

/**
Expand Down Expand Up @@ -269,25 +270,18 @@ public function parse(Parser $parser, TokensList $list): void

public function build(): string
{
$initial = true;
$str = 'WITH';
$str = 'WITH ';

if ($this->options !== null && $this->options->options !== []) {
$str .= ' ' . $this->options->build();
$str .= $this->options->build() . ' ';
}

foreach ($this->withers as $wither) {
$str .= $initial ? ' ' : ', ';
$str .= $wither->build();
$initial = false;
if ($this->withers !== []) {
$str .= implode(', ', $this->withers) . ' ';
}

$str .= ' ';

if ($this->cteStatementParser) {
foreach ($this->cteStatementParser->statements as $statement) {
$str .= $statement->build();
}
$str .= implode('', $this->cteStatementParser->statements);
}

return $str;
Expand Down

0 comments on commit 562773c

Please sign in to comment.