Skip to content

Commit d6d1434

Browse files
authored
Merge pull request #8970 from kenjis/refactor-orderBy
refactor: BaseBuilder::orderBy()
2 parents cd46db1 + 4c01499 commit d6d1434

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

system/Database/BaseBuilder.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,11 +1448,12 @@ public function orHaving($key, $value = null, ?bool $escape = null)
14481448
*/
14491449
public function orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
14501450
{
1451-
$qbOrderBy = [];
14521451
if ($orderBy === '') {
14531452
return $this;
14541453
}
14551454

1455+
$qbOrderBy = [];
1456+
14561457
$direction = strtoupper(trim($direction));
14571458

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

1466-
if (! is_bool($escape)) {
1467+
if ($escape === null) {
14671468
$escape = $this->db->protectIdentifiers;
14681469
}
14691470

@@ -1474,8 +1475,6 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
14741475
'escape' => false,
14751476
];
14761477
} else {
1477-
$qbOrderBy = [];
1478-
14791478
foreach (explode(',', $orderBy) as $field) {
14801479
$qbOrderBy[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE))
14811480
? [

0 commit comments

Comments
 (0)