Skip to content

Commit e2dc2a9

Browse files
committed
Remove getUnsortedSqlAndSortByKeyDropDown()
This was stupid abstraction. This method did 2 things. When the code that prepares unsorted SQL is moved out of this method, the rest can be absorbed by getSortByKeyDropDown(). This method didn't declare any local variables, it took parameters that were just passed along to other methods. The code to get unsorted SQL was just a single instruction that was self-explanatory. Indexes relied on properties so they didn't need to be a parameter to the other method. This method only added complexity instead of reducing it. Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent 7a735dd commit e2dc2a9

2 files changed

Lines changed: 23 additions & 61 deletions

File tree

libraries/classes/Display/Results.php

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,61 +1176,29 @@ private function getTableHeaders(
11761176
];
11771177
}
11781178

1179-
/**
1180-
* Prepare unsorted sql query and sort by key drop down
1181-
*
1182-
* @see getTableHeaders()
1183-
*
1184-
* @param array $analyzedSqlResults analyzed sql results
1185-
* @param array|null $sortExpression sort expression
1186-
*
1187-
* @return array two element array - $unsorted_sql_query, $drop_down_html
1188-
* @psalm-return array{string, array{hidden_fields?: array, options?: array}}
1189-
*/
1190-
private function getUnsortedSqlAndSortByKeyDropDown(
1191-
array $analyzedSqlResults,
1192-
?array $sortExpression
1193-
) {
1194-
$dropDownData = [];
1195-
1196-
$unsortedSqlQuery = Query::replaceClause(
1197-
$analyzedSqlResults['statement'],
1198-
$analyzedSqlResults['parser']->list,
1199-
'ORDER BY',
1200-
''
1201-
);
1202-
1203-
// Data is sorted by indexes only if it there is only one table.
1204-
if ($this->isSelect($analyzedSqlResults)) {
1205-
// grab indexes data:
1206-
$indexes = Index::getFromTable($this->properties['table'], $this->properties['db']);
1207-
1208-
// do we have any index?
1209-
if ($indexes !== []) {
1210-
$dropDownData = $this->getSortByKeyDropDown($indexes, $sortExpression, $unsortedSqlQuery);
1211-
}
1212-
}
1213-
1214-
return [$unsortedSqlQuery, $dropDownData];
1215-
}
1216-
12171179
/**
12181180
* Prepare sort by key dropdown - html code segment
12191181
*
12201182
* @see getTableHeaders()
12211183
*
1222-
* @param Index[] $indexes the indexes of the table for sort criteria
12231184
* @param array|null $sortExpression the sort expression
12241185
* @param string $unsortedSqlQuery the unsorted sql query
12251186
*
12261187
* @return array[]
1227-
* @psalm-return array{hidden_fields:array, options:array}
1188+
* @psalm-return array{hidden_fields?:array, options?:array}
12281189
*/
12291190
private function getSortByKeyDropDown(
1230-
$indexes,
12311191
?array $sortExpression,
1232-
$unsortedSqlQuery
1192+
string $unsortedSqlQuery
12331193
): array {
1194+
// grab indexes data:
1195+
$indexes = Index::getFromTable($this->properties['table'], $this->properties['db']);
1196+
1197+
// do we have any index?
1198+
if ($indexes === []) {
1199+
return [];
1200+
}
1201+
12341202
$hiddenFields = [
12351203
'db' => $this->properties['db'],
12361204
'table' => $this->properties['table'],
@@ -3706,11 +3674,20 @@ public function getTable(
37063674
$sortByKeyData = [];
37073675
// can the result be sorted?
37083676
if ($displayParts['sort_lnk'] == '1' && isset($analyzedSqlResults['statement'])) {
3709-
// At this point, $sort_expression is an array
3710-
[$unsortedSqlQuery, $sortByKeyData] = $this->getUnsortedSqlAndSortByKeyDropDown(
3711-
$analyzedSqlResults,
3712-
$sortExpression
3677+
$unsortedSqlQuery = Query::replaceClause(
3678+
$analyzedSqlResults['statement'],
3679+
$analyzedSqlResults['parser']->list,
3680+
'ORDER BY',
3681+
''
37133682
);
3683+
3684+
// Data is sorted by indexes only if there is only one table.
3685+
if ($this->isSelect($analyzedSqlResults)) {
3686+
$sortByKeyData = $this->getSortByKeyDropDown(
3687+
$sortExpression,
3688+
$unsortedSqlQuery
3689+
);
3690+
}
37143691
}
37153692

37163693
$navigation = [];

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,21 +3455,6 @@ parameters:
34553455
count: 1
34563456
path: libraries/classes/Display/Results.php
34573457

3458-
-
3459-
message: "#^Method PhpMyAdmin\\\\Display\\\\Results\\:\\:getUnsortedSqlAndSortByKeyDropDown\\(\\) has parameter \\$analyzedSqlResults with no value type specified in iterable type array\\.$#"
3460-
count: 1
3461-
path: libraries/classes/Display/Results.php
3462-
3463-
-
3464-
message: "#^Method PhpMyAdmin\\\\Display\\\\Results\\:\\:getUnsortedSqlAndSortByKeyDropDown\\(\\) has parameter \\$sortExpression with no value type specified in iterable type array\\.$#"
3465-
count: 1
3466-
path: libraries/classes/Display/Results.php
3467-
3468-
-
3469-
message: "#^Method PhpMyAdmin\\\\Display\\\\Results\\:\\:getUnsortedSqlAndSortByKeyDropDown\\(\\) return type has no value type specified in iterable type array\\.$#"
3470-
count: 2
3471-
path: libraries/classes/Display/Results.php
3472-
34733458
-
34743459
message: "#^Method PhpMyAdmin\\\\Display\\\\Results\\:\\:getUrlSqlQuery\\(\\) has parameter \\$analyzedSqlResults with no value type specified in iterable type array\\.$#"
34753460
count: 1

0 commit comments

Comments
 (0)