Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit d11e69a

Browse files
committed
Convert only strings, let the driver fail for int values
1 parent fdba54f commit d11e69a

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/Query/Builder.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,13 @@ public function distinct($column = false)
518518
public function orderBy($column, $direction = 'asc')
519519
{
520520
if (is_string($direction)) {
521-
$direction = match (strtolower($direction)) {
522-
'asc' => 1,
523-
'desc' => -1,
524-
default => throw new \InvalidArgumentException(sprintf('Order direction must be either "asc" or "desc", "%s" given.', $direction)),
521+
$direction = match ($direction) {
522+
'asc', 'ASC' => 1,
523+
'desc', 'DESC' => -1,
524+
default => throw new \InvalidArgumentException('Order direction must be "asc" or "desc".'),
525525
};
526526
}
527527

528-
if ($direction !== 1 && $direction !== -1) {
529-
throw new \InvalidArgumentException(sprintf('Order direction must be either 1 or -1, "%s" given.', $direction));
530-
}
531-
532528
if ($column == 'natural') {
533529
$this->orders['$natural'] = $direction;
534530
} else {

tests/QueryBuilderTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -864,16 +864,10 @@ public function testCursor()
864864
}
865865
}
866866

867-
/**
868-
* @testWith ["dasc"]
869-
* [0]
870-
* [10]
871-
* [true]
872-
*/
873-
public function testOrderByInvalidDirection($direction)
867+
public function testOrderByInvalidDirection()
874868
{
875869
$this->expectException(\InvalidArgumentException::class);
876-
$this->expectExceptionMessage('Order direction must be either ');
877-
DB::collection('items')->orderBy('_id', $direction)->get();
870+
$this->expectExceptionMessage('Order direction must be "asc" or "desc"');
871+
DB::collection('items')->orderBy('_id', 'dasc')->get();
878872
}
879873
}

0 commit comments

Comments
 (0)