Skip to content

Commit

Permalink
Fixed StyleCI/PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
frknakk committed Oct 27, 2023
1 parent dcc351d commit 9823017
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/QueryDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1026,11 +1026,12 @@ protected function applyScoutSearch(string $search_keyword): bool
* @param string $keyName
* @param array $orderedKeys
* @return void
*
* @throws \Exception If the database driver is unsupported.
*/
protected function applyFixedOrderingToQuery(string $keyName, array $orderedKeys)
{
$connection = $this->query->getConnection();
$connection = $this->getConnection();
$driver_name = $connection->getDriverName();

// Escape keyName and orderedKeys
Expand All @@ -1040,36 +1041,35 @@ protected function applyFixedOrderingToQuery(string $keyName, array $orderedKeys
return $connection->escape($value);
});

switch ($driver_name)
{
switch ($driver_name) {
case 'mysql':
// MySQL
$this->query->orderByRaw("FIELD($keyName, " . $orderedKeys->implode(',') . ")");
break;

/*
TODO: test implementations, fix if necessary and uncomment
case 'pgsql':
// PostgreSQL
$this->query->orderByRaw("array_position(ARRAY[" . $orderedKeys->implode(',') . "], $keyName)");
$this->query->orderByRaw("FIELD($keyName, ".$orderedKeys->implode(',').')');
break;

case 'sqlite':
case 'sqlsrv':
// SQLite & Microsoft SQL Server
// should be generally compatible with all drivers using SQL syntax (but ugly solution)
$this->query->orderByRaw(
"CASE $keyName "
.
$orderedKeys
->map(fn($value, $index) => "WHEN $keyName = $value THEN $index")
->implode(' ')
.
" END"
);
break;
*/
/*
TODO: test implementations, fix if necessary and uncomment
case 'pgsql':
// PostgreSQL
$this->query->orderByRaw("array_position(ARRAY[" . $orderedKeys->implode(',') . "], $keyName)");
break;
case 'sqlite':
case 'sqlsrv':
// SQLite & Microsoft SQL Server
// should be generally compatible with all drivers using SQL syntax (but ugly solution)
$this->query->orderByRaw(
"CASE $keyName "
.
$orderedKeys
->map(fn($value, $index) => "WHEN $keyName = $value THEN $index")
->implode(' ')
.
" END"
);
break;
*/

default:
throw new \Exception("Unsupported database driver: $driver_name");
Expand Down

0 comments on commit 9823017

Please sign in to comment.