Skip to content

Commit

Permalink
Merge pull request #8970 from kenjis/refactor-orderBy
Browse files Browse the repository at this point in the history
refactor: BaseBuilder::orderBy()
  • Loading branch information
kenjis authored Jun 19, 2024
2 parents cd46db1 + 4c01499 commit d6d1434
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1448,11 +1448,12 @@ public function orHaving($key, $value = null, ?bool $escape = null)
*/
public function orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
{
$qbOrderBy = [];
if ($orderBy === '') {
return $this;
}

$qbOrderBy = [];

$direction = strtoupper(trim($direction));

if ($direction === 'RANDOM') {
Expand All @@ -1463,7 +1464,7 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
$direction = in_array($direction, ['ASC', 'DESC'], true) ? ' ' . $direction : '';
}

if (! is_bool($escape)) {
if ($escape === null) {
$escape = $this->db->protectIdentifiers;
}

Expand All @@ -1474,8 +1475,6 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
'escape' => false,
];
} else {
$qbOrderBy = [];

foreach (explode(',', $orderBy) as $field) {
$qbOrderBy[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE))
? [
Expand Down

0 comments on commit d6d1434

Please sign in to comment.