Skip to content

Commit

Permalink
Merge #606 - Simplify WithStatement::build()
Browse files Browse the repository at this point in the history
Pull-request: #606
Signed-off-by: William Desportes <[email protected]>
  • Loading branch information
williamdes committed Jan 19, 2025
2 parents d46ae48 + 562773c commit ab0d173
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 ab0d173

Please sign in to comment.