Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ final class Context
')' => 16,
'.' => 16,
',' => 16,
'->' => 16,
'->>' => 16,
';' => 16,
];

Expand Down
11 changes: 7 additions & 4 deletions src/Utils/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,15 @@ public function formatList(TokensList $list): string
} elseif (
$prev->keyword === 'DELIMITER'
|| ! (
($prev->type === TokenType::Operator && ($prev->value === '.' || $prev->value === '('))
// No space after . (
($prev->type === TokenType::Operator
&& ($prev->value === '.' || $prev->value === '('
|| $prev->value === '->' || $prev->value === '->>'))
// No space after punctuation and JSON operators.
|| ($curr->type === TokenType::Operator
&& ($curr->value === '.' || $curr->value === ','
|| $curr->value === '(' || $curr->value === ')'))
// No space before . , ( )
|| $curr->value === '(' || $curr->value === ')'
|| $curr->value === '->' || $curr->value === '->>'))
// No space before punctuation and JSON operators.
|| $curr->type === TokenType::Delimiter && mb_strlen((string) $curr->value, 'UTF-8') < 2
)
) {
Expand Down
15 changes: 15 additions & 0 deletions tests/Utils/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ public static function formatQueriesProviders(): array
'<span class="sql-reserved">WHERE</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;<span class="sql-number">1</span>',
],
'json operator' => [
'query' => 'SELECT details->\'$."first_name"\' FROM users',
'text' => 'SELECT' . "\n" .
' details->\'$."first_name"\'' . "\n" .
'FROM' . "\n" .
' users',
'cli' => "\x1b[35mSELECT\n" .
" \x1b[39mdetails->\x1b[91m'$.\"first_name\"'\n" .
"\x1b[35mFROM\n" .
" \x1b[39musers\x1b[0m",
'html' => '<span class="sql-reserved">SELECT</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;details-&gt;<span class="sql-string">\'$."first_name"\'</span><br/>' .
'<span class="sql-reserved">FROM</span><br/>' .
'&nbsp;&nbsp;&nbsp;&nbsp;users',
],
'typical' => [
'query' => 'SELECT id, if(id=1,"Si","No") from `tbl` where id = 0 or ' .
'id = 1 group by id order by id desc limit 1 offset 0',
Expand Down