Visitar URL original
Merge pull request #17269 from kamil-tekiela/autofix-1 · phpmyadmin/phpmyadmin@24224f9 · GitHub
Skip to content

Commit 24224f9

Browse files
Merge pull request #17269 from kamil-tekiela/autofix-1
A collection of small code refactorings
2 parents 3acaca5 + 73b7094 commit 24224f9

11 files changed

Lines changed: 77 additions & 118 deletions

File tree

‎libraries/classes/Controllers/Export/ExportController.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,7 @@ public function __invoke(ServerRequest $request): void
321321
} elseif ($export_type === 'database' && strlen($db) > 0) {
322322
$errorUrl = Url::getFromRoute('/database/export', ['db' => $db]);
323323
// Check if we have something to export
324-
if (isset($table_select)) {
325-
$tables = $table_select;
326-
} else {
327-
$tables = [];
328-
}
324+
$tables = $table_select ?? [];
329325
} elseif ($export_type === 'table' && strlen($db) > 0 && strlen($table) > 0) {
330326
$errorUrl = Url::getFromRoute('/table/export', [
331327
'db' => $db,

‎libraries/classes/Controllers/Table/OperationsController.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,7 @@ public function __invoke(): void
246246
$warning_messages = $this->operations->getWarningMessagesArray();
247247
}
248248

249-
if (
250-
isset($_POST['tbl_collation'], $_POST['change_all_collations'])
251-
&& ! empty($_POST['tbl_collation'])
252-
&& ! empty($_POST['change_all_collations'])
253-
) {
249+
if (! empty($_POST['tbl_collation']) && ! empty($_POST['change_all_collations'])) {
254250
$this->operations->changeAllColumnsCollation($db, $table, $_POST['tbl_collation']);
255251
}
256252

‎libraries/classes/Controllers/View/CreateController.php‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,8 @@ public function __invoke(): void
132132

133133
$sql_query .= $sep . ' AS ' . $_POST['view']['as'];
134134

135-
if (isset($_POST['view']['with'])) {
136-
if (in_array($_POST['view']['with'], $view_with_options)) {
137-
$sql_query .= $sep . ' WITH ' . $_POST['view']['with']
138-
. ' CHECK OPTION';
139-
}
135+
if (isset($_POST['view']['with']) && in_array($_POST['view']['with'], $view_with_options)) {
136+
$sql_query .= $sep . ' WITH ' . $_POST['view']['with'] . ' CHECK OPTION';
140137
}
141138

142139
if (! $this->dbi->tryQuery($sql_query)) {

‎libraries/classes/DatabaseInterface.php‎

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function tryQuery(
205205
int $options = self::QUERY_BUFFERED,
206206
bool $cache_affected_rows = true
207207
) {
208-
$debug = isset($GLOBALS['cfg']['DBG']) ? $GLOBALS['cfg']['DBG']['sql'] : false;
208+
$debug = isset($GLOBALS['cfg']['DBG']) && $GLOBALS['cfg']['DBG']['sql'];
209209
if (! isset($this->links[$link])) {
210210
return false;
211211
}
@@ -323,7 +323,7 @@ public function getTables(string $database, $link = self::CONNECT_USER): array
323323
* @param bool|int $limit_count number of tables to return
324324
* @param string $sort_by table attribute to sort by
325325
* @param string $sort_order direction to sort (ASC or DESC)
326-
* @param string $table_type whether table or view
326+
* @param string|null $table_type whether table or view
327327
* @param mixed $link link type
328328
*
329329
* @return array list of tables in given db(s)
@@ -446,11 +446,10 @@ static function ($a, $b) {
446446
// If permissions are wrong on even one database directory,
447447
// information_schema does not return any table info for any database
448448
// this is why we fall back to SHOW TABLE STATUS even for MySQL >= 50002
449-
if (empty($tables)) {
449+
if ($tables === []) {
450+
$sql = 'SHOW TABLE STATUS FROM ' . Util::backquote($database);
450451
if ($table || ($tbl_is_group === true) || $table_type) {
451-
$sql = 'SHOW TABLE STATUS FROM '
452-
. Util::backquote($database)
453-
. ' WHERE';
452+
$sql .= ' WHERE';
454453
$needAnd = false;
455454
if ($table || ($tbl_is_group === true)) {
456455
if (is_array($table)) {
@@ -488,9 +487,6 @@ static function ($a, $b) {
488487
$sql .= " `Comment` != 'VIEW'";
489488
}
490489
}
491-
} else {
492-
$sql = 'SHOW TABLE STATUS FROM '
493-
. Util::backquote($database);
494490
}
495491

496492
$each_tables = $this->fetchResult($sql, 'Name', null, $link);
@@ -605,14 +601,14 @@ public function getVirtualTables(string $db): array
605601
/**
606602
* returns array with databases containing extended infos about them
607603
*
608-
* @param string $database database
609-
* @param bool $force_stats retrieve stats also for MySQL < 5
610-
* @param int $link link type
611-
* @param string $sort_by column to order by
612-
* @param string $sort_order ASC or DESC
613-
* @param int $limit_offset starting offset for LIMIT
614-
* @param bool|int $limit_count row count for LIMIT or true
615-
* for $GLOBALS['cfg']['MaxDbList']
604+
* @param string|null $database database
605+
* @param bool $force_stats retrieve stats also for MySQL < 5
606+
* @param int $link link type
607+
* @param string $sort_by column to order by
608+
* @param string $sort_order ASC or DESC
609+
* @param int $limit_offset starting offset for LIMIT
610+
* @param bool|int $limit_count row count for LIMIT or true
611+
* for $GLOBALS['cfg']['MaxDbList']
616612
*
617613
* @return array
618614
*
@@ -792,10 +788,10 @@ public function getColumnMapFromSql(string $sql_query, array $view_columns = [])
792788
* returns detailed array with all columns for given table in database,
793789
* or all tables/databases
794790
*
795-
* @param string $database name of database
796-
* @param string $table name of table to retrieve columns from
797-
* @param string $column name of specific column
798-
* @param mixed $link mysql link resource
791+
* @param string|null $database name of database
792+
* @param string|null $table name of table to retrieve columns from
793+
* @param string|null $column name of specific column
794+
* @param mixed $link mysql link resource
799795
*
800796
* @return array
801797
*/
@@ -1051,11 +1047,7 @@ public function setVariable(
10511047
*/
10521048
public function postConnect(): void
10531049
{
1054-
$version = $this->fetchSingleRow(
1055-
'SELECT @@version, @@version_comment',
1056-
DbalInterface::FETCH_ASSOC,
1057-
self::CONNECT_USER
1058-
);
1050+
$version = $this->fetchSingleRow('SELECT @@version, @@version_comment');
10591051

10601052
if (is_array($version)) {
10611053
$this->versionString = $version['@@version'] ?? '';
@@ -1480,9 +1472,9 @@ public function getDefinition(
14801472
* returns details about the PROCEDUREs or FUNCTIONs for a specific database
14811473
* or details about a specific routine
14821474
*
1483-
* @param string $db db name
1484-
* @param string $which PROCEDURE | FUNCTION or null for both
1485-
* @param string $name name of the routine (to fetch a specific routine)
1475+
* @param string $db db name
1476+
* @param string|null $which PROCEDURE | FUNCTION or null for both
1477+
* @param string $name name of the routine (to fetch a specific routine)
14861478
*
14871479
* @return array information about PROCEDUREs or FUNCTIONs
14881480
*/
@@ -1592,7 +1584,7 @@ public function getEvents(string $db, string $name = ''): array
15921584
*
15931585
* @return array information about triggers (may be empty)
15941586
*/
1595-
public function getTriggers(string $db, string $table = '', $delimiter = '//')
1587+
public function getTriggers(string $db, string $table = '', string $delimiter = '//'): array
15961588
{
15971589
$result = [];
15981590
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
@@ -1822,7 +1814,7 @@ public function getLowerCaseNames()
18221814
* @param int $mode Connection mode on of CONNECT_USER, CONNECT_CONTROL
18231815
* or CONNECT_AUXILIARY.
18241816
* @param array|null $server Server information like host/port/socket/persistent
1825-
* @param int $target How to store connection link, defaults to $mode
1817+
* @param int|null $target How to store connection link, defaults to $mode
18261818
*
18271819
* @return mixed false on error or a connection object on success
18281820
*/

‎libraries/classes/Dbal/DbalInterface.php‎

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function getTables(string $database, $link = DatabaseInterface::CONNECT_U
9292
* @param bool|int $limit_count number of tables to return
9393
* @param string $sort_by table attribute to sort by
9494
* @param string $sort_order direction to sort (ASC or DESC)
95-
* @param string $table_type whether table or view
95+
* @param string|null $table_type whether table or view
9696
* @param mixed $link link type
9797
*
9898
* @return array list of tables in given db(s)
@@ -123,15 +123,14 @@ public function getVirtualTables(string $db): array;
123123
/**
124124
* returns array with databases containing extended infos about them
125125
*
126-
* @param string $database database
127-
* @param bool $force_stats retrieve stats also for MySQL < 5
128-
* @param int $link link type
129-
* @param string $sort_by column to order by
130-
* @param string $sort_order ASC or DESC
131-
* @param int $limit_offset starting offset for LIMIT
132-
* @param bool|int $limit_count row count for LIMIT or true
133-
* for
134-
* $GLOBALS['cfg']['MaxDbList']
126+
* @param string|null $database database
127+
* @param bool $force_stats retrieve stats also for MySQL < 5
128+
* @param int $link link type
129+
* @param string $sort_by column to order by
130+
* @param string $sort_order ASC or DESC
131+
* @param int $limit_offset starting offset for LIMIT
132+
* @param bool|int $limit_count row count for LIMIT or true
133+
* for $GLOBALS['cfg']['MaxDbList']
135134
*
136135
* @return array
137136
*
@@ -161,10 +160,10 @@ public function getColumnMapFromSql(string $sql_query, array $view_columns = [])
161160
* returns detailed array with all columns for given table in database,
162161
* or all tables/databases
163162
*
164-
* @param string $database name of database
165-
* @param string $table name of table to retrieve columns from
166-
* @param string $column name of specific column
167-
* @param mixed $link mysql link resource
163+
* @param string|null $database name of database
164+
* @param string|null $table name of table to retrieve columns from
165+
* @param string|null $column name of specific column
166+
* @param mixed $link mysql link resource
168167
*
169168
* @return array
170169
*/
@@ -449,9 +448,9 @@ public function getDefinition(
449448
* returns details about the PROCEDUREs or FUNCTIONs for a specific database
450449
* or details about a specific routine
451450
*
452-
* @param string $db db name
453-
* @param string $which PROCEDURE | FUNCTION or null for both
454-
* @param string $name name of the routine (to fetch a specific routine)
451+
* @param string $db db name
452+
* @param string|null $which PROCEDURE | FUNCTION or null for both
453+
* @param string $name name of the routine (to fetch a specific routine)
455454
*
456455
* @return array information about ROCEDUREs or FUNCTIONs
457456
*/
@@ -476,7 +475,7 @@ public function getEvents(string $db, string $name = ''): array;
476475
*
477476
* @return array information about triggers (may be empty)
478477
*/
479-
public function getTriggers(string $db, string $table = '', $delimiter = '//');
478+
public function getTriggers(string $db, string $table = '', string $delimiter = '//'): array;
480479

481480
/**
482481
* gets the current user with host
@@ -516,7 +515,7 @@ public function getLowerCaseNames();
516515
* @param int $mode Connection mode on of CONNECT_USER, CONNECT_CONTROL
517516
* or CONNECT_AUXILIARY.
518517
* @param array|null $server Server information like host/port/socket/persistent
519-
* @param int $target How to store connection link, defaults to $mode
518+
* @param int|null $target How to store connection link, defaults to $mode
520519
*
521520
* @return mixed false on error or a connection object on success
522521
*/

‎libraries/classes/Display/Results.php‎

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ private function isSelect(array $analyzedSqlResults): bool
716716
* @param bool $back whether 'begin' or 'previous'
717717
* @param string $onsubmit optional onsubmit clause
718718
* @param string $inputForRealEnd optional hidden field for special treatment
719-
* @param string $onclick optional onclick clause
720719
*
721720
* @return string html content
722721
*/
@@ -727,8 +726,7 @@ private function getTableNavigationButton(
727726
$htmlSqlQuery,
728727
$back,
729728
$onsubmit = '',
730-
$inputForRealEnd = '',
731-
$onclick = ''
729+
$inputForRealEnd = ''
732730
): string {
733731
$captionOutput = '';
734732
if ($back) {
@@ -760,7 +758,6 @@ private function getTableNavigationButton(
760758
'caption_output' => $captionOutput,
761759
'title' => $title,
762760
'onsubmit' => $onsubmit,
763-
'onclick' => $onclick,
764761
]);
765762
}
766763

@@ -791,12 +788,7 @@ private function getHtmlPageSelector(): array
791788
'pos',
792789
$_SESSION['tmpval']['max_rows'],
793790
$pageNow,
794-
$nbTotalPage,
795-
200,
796-
5,
797-
5,
798-
20,
799-
10
791+
$nbTotalPage
800792
),
801793
]);
802794
}
@@ -1434,10 +1426,9 @@ private function getOptionsBlock(): array
14341426
if (
14351427
isset($_SESSION['tmpval']['possible_as_geometry'])
14361428
&& $_SESSION['tmpval']['possible_as_geometry'] == false
1429+
&& $_SESSION['tmpval']['geoOption'] === self::GEOMETRY_DISP_GEOM
14371430
) {
1438-
if ($_SESSION['tmpval']['geoOption'] === self::GEOMETRY_DISP_GEOM) {
1439-
$_SESSION['tmpval']['geoOption'] = self::GEOMETRY_DISP_WKT;
1440-
}
1431+
$_SESSION['tmpval']['geoOption'] = self::GEOMETRY_DISP_WKT;
14411432
}
14421433

14431434
return [
@@ -1916,7 +1907,7 @@ private function getSortOrderHiddenInputs(
19161907
$multipleUrlParams['sql_signature'] = Core::signSqlQuery($multipleUrlParams['sql_query']);
19171908

19181909
$urlRemoveOrder = Url::getFromRoute('/sql', $multipleUrlParams);
1919-
if ($numberOfClausesFound !== null && $numberOfClausesFound === 0) {
1910+
if ($numberOfClausesFound === 0) {
19201911
$urlRemoveOrder .= '&discard_remembered_sort=1';
19211912
}
19221913

@@ -2349,30 +2340,27 @@ private function getTableBody(
23492340

23502341
// 3. Displays the modify/delete links on the right if required
23512342
if (
2352-
($displayParts['edit_lnk'] != self::NO_EDIT_OR_DELETE)
2353-
|| ($displayParts['del_lnk'] != self::NO_EDIT_OR_DELETE)
2343+
($displayParts['edit_lnk'] != self::NO_EDIT_OR_DELETE
2344+
|| $displayParts['del_lnk'] != self::NO_EDIT_OR_DELETE)
2345+
&& ($GLOBALS['cfg']['RowActionLinks'] === self::POSITION_RIGHT
2346+
|| $GLOBALS['cfg']['RowActionLinks'] === self::POSITION_BOTH)
23542347
) {
2355-
if (
2356-
($GLOBALS['cfg']['RowActionLinks'] === self::POSITION_RIGHT)
2357-
|| ($GLOBALS['cfg']['RowActionLinks'] === self::POSITION_BOTH)
2358-
) {
2359-
$tableBodyHtml .= $this->template->render('display/results/checkbox_and_links', [
2360-
'position' => self::POSITION_RIGHT,
2361-
'has_checkbox' => $deleteUrl && $displayParts['del_lnk'] !== self::KILL_PROCESS,
2362-
'edit' => [
2363-
'url' => $editUrl,
2364-
'string' => $editString,
2365-
'clause_is_unique' => $clauseIsUnique ?? true,
2366-
],
2367-
'copy' => ['url' => $copyUrl, 'string' => $copyString],
2368-
'delete' => ['url' => $deleteUrl, 'string' => $deleteString],
2369-
'row_number' => $rowNumber,
2370-
'where_clause' => $whereClause ?? '',
2371-
'condition' => json_encode($conditionArray ?? []),
2372-
'is_ajax' => ResponseRenderer::getInstance()->isAjax(),
2373-
'js_conf' => $jsConf ?? '',
2374-
]);
2375-
}
2348+
$tableBodyHtml .= $this->template->render('display/results/checkbox_and_links', [
2349+
'position' => self::POSITION_RIGHT,
2350+
'has_checkbox' => $deleteUrl && $displayParts['del_lnk'] !== self::KILL_PROCESS,
2351+
'edit' => [
2352+
'url' => $editUrl,
2353+
'string' => $editString,
2354+
'clause_is_unique' => $clauseIsUnique ?? true,
2355+
],
2356+
'copy' => ['url' => $copyUrl, 'string' => $copyString],
2357+
'delete' => ['url' => $deleteUrl, 'string' => $deleteString],
2358+
'row_number' => $rowNumber,
2359+
'where_clause' => $whereClause ?? '',
2360+
'condition' => json_encode($conditionArray ?? []),
2361+
'is_ajax' => ResponseRenderer::getInstance()->isAjax(),
2362+
'js_conf' => $jsConf ?? '',
2363+
]);
23762364
}
23772365

23782366
$tableBodyHtml .= '</tr>';
@@ -3354,7 +3342,7 @@ private function getDataCellForNonNumericColumns(
33543342
// some results of PROCEDURE ANALYSE() are reported as
33553343
// being BINARY but they are quite readable,
33563344
// so don't treat them as BINARY
3357-
} elseif ($meta->isBinary() && ! ($isAnalyse === true)) {
3345+
} elseif ($meta->isBinary() && $isAnalyse !== true) {
33583346
// we show the BINARY or BLOB message and field's size
33593347
// (or maybe use a transformation)
33603348
$binaryOrBlob = 'BLOB';
@@ -3651,7 +3639,7 @@ public function getTable(
36513639

36523640
// 2.1 Prepares a messages with position information
36533641
$sqlQueryMessage = '';
3654-
if (($displayParts['nav_bar'] == '1')) {
3642+
if ($displayParts['nav_bar'] == '1') {
36553643
$message = $this->setMessageInformation(
36563644
$sortedColumnMessage,
36573645
$analyzedSqlResults,

‎libraries/classes/InsertEdit.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ private function getHtmlForInsertEditFormColumn(
20602060
$vkey,
20612061
$insertMode,
20622062
array $currentRow,
2063-
&$oRows,
2063+
$oRows,
20642064
&$tabindex,
20652065
$columnsCnt,
20662066
$isUpload,

‎libraries/classes/Setup/Index.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static function messagesEnd(): void
7171
{
7272
foreach ($_SESSION['messages'] as &$messages) {
7373
$remove_ids = [];
74-
foreach ($messages as $id => &$msg) {
74+
foreach ($messages as $id => $msg) {
7575
if ($msg['active'] != false) {
7676
continue;
7777
}

0 commit comments

Comments
 (0)