Skip to content

Commit

Permalink
fix cmp after upper kw revert
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 13, 2024
1 parent 8e9d3a0 commit 6e642b2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/SqlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use function str_repeat;
use function str_replace;
use function strlen;
use function strtoupper;
use function trim;

use const PHP_SAPI;
Expand Down Expand Up @@ -253,25 +254,25 @@ public function format(string $string, string $indentString = ' '): string
$highlighted = preg_replace('/\s+/', ' ', $highlighted);
}

//if SQL 'LIMIT' clause, start variable to reset newline
if ($token->value() === 'LIMIT' && ! $inlineParentheses) {
// if SQL 'LIMIT' clause, start variable to reset newline
if (strtoupper($token->value()) === 'LIMIT' && ! $inlineParentheses) {
$clauseLimit = true;
}
} elseif ($token->value() === 'CASE') {
} elseif (strtoupper($token->value()) === 'CASE') {
$increaseBlockIndent = true;
} elseif (in_array($token->value(), ['WHEN', 'THEN', 'ELSE', 'END'], true)) {
if ($token->value() !== 'THEN') {
} elseif (in_array(strtoupper($token->value()), ['WHEN', 'THEN', 'ELSE', 'END'], true)) {
if (strtoupper($token->value()) !== 'THEN') {
array_shift($indentTypes);
$indentLevel--;

$prevNotWhitespaceToken = $cursor->subCursor()->previous(Token::TOKEN_TYPE_WHITESPACE);
if ($prevNotWhitespaceToken !== null && $prevNotWhitespaceToken->value() !== 'CASE') {
if ($prevNotWhitespaceToken !== null && strtoupper($prevNotWhitespaceToken->value()) !== 'CASE') {
$return = rtrim($return, ' ');
$return .= "\n" . str_repeat($tab, $indentLevel);
}
}

if ($token->value() === 'THEN' || $token->value() === 'ELSE') {
if (strtoupper($token->value()) === 'THEN' || strtoupper($token->value()) === 'ELSE') {
$newline = true;
$increaseBlockIndent = true;
}
Expand Down

0 comments on commit 6e642b2

Please sign in to comment.