Skip to content

Commit 2b35303

Browse files
Remove redundant code (#18063)
PHPStorm has been a little annoying with showing all these code issues. I took some time to analyse most of them and fix whichever were easy to fix. This kind of change should improve future maintenance as developers do not need to wonder what a line of code does. Code that has no impact on functionality should be removed. * Remove redundant variables * Invert condition for better clarity * Remove some of the redundant casts * Replace switch with an if * Fix foreach variable * Remove redundant variable concat * Remove redundant concats * Replace for loop with str_repeat * Remove always true param * Turn property $position into local var * Turn Pdf properties into local vars * Remove unused properties in Pdf * Change ternary into condition * Remove redundant assignments They are immediately overwritten with a different value. * Redundant array append * Collapse if statements into assignments * Use boolean constants instead of variables * Remove unneeded parameter * Remove null-coalesce * Unnecessary assignment * Remove redundant isset * Remove readOnly flag for InsertEdit fields * Remove function_exists and $mode var * Remove duplicate condition * Remove redundant elseif * Remove redundant isset * Use hasBodyParam() * Simplify isRoutesCacheFileValid() Psalm complains but is wrong. #18063 --------- Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent c351696 commit 2b35303

47 files changed

Lines changed: 189 additions & 323 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libraries/classes/Charsets/Collation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ private function buildDescription(): string
171171
/* Next will be variant unless changed later */
172172
$level = 4;
173173
/* Locale name or code */
174-
$found = true;
175-
[$name, $level, $found] = $this->getNameForLevel1($unicode, $unknown, $part, $name, $level, $found);
174+
[$name, $level, $found] = $this->getNameForLevel1($unicode, $unknown, $part, $name, $level);
176175
if ($found) {
177176
continue;
178177
}
@@ -428,9 +427,10 @@ private function getNameForLevel1(
428427
bool $unknown,
429428
string $part,
430429
string $name,
431-
int $level,
432-
bool $found
430+
int $level
433431
): array {
432+
$found = true;
433+
434434
switch ($part) {
435435
case 'general':
436436
break;

libraries/classes/Config/FormDisplay.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ public function getDisplay(
287287
$path,
288288
$workPath,
289289
$translatedPath,
290-
true,
291290
$userPrefsAllow,
292291
$jsDefault
293292
);
@@ -315,19 +314,18 @@ public function getDisplay(
315314
/**
316315
* Prepares data for input field display and outputs HTML code
317316
*
318-
* @param Form $form Form object
319-
* @param string $field field name as it appears in $form
320-
* @param string $systemPath field path, eg. Servers/1/verbose
321-
* @param string $workPath work path, eg. Servers/4/verbose
322-
* @param string $translatedPath work path changed so that it can be
323-
* used as XHTML id
324-
* @param bool $showRestoreDefault whether show "restore default" button
325-
* besides the input field
326-
* @param bool|null $userPrefsAllow whether user preferences are enabled
327-
* for this field (null - no support,
328-
* true/false - enabled/disabled)
329-
* @param array $jsDefault array which stores JavaScript code
330-
* to be displayed
317+
* @param Form $form Form object
318+
* @param string $field field name as it appears in $form
319+
* @param string $systemPath field path, eg. Servers/1/verbose
320+
* @param string $workPath work path, eg. Servers/4/verbose
321+
* @param string $translatedPath work path changed so that it can be
322+
* used as XHTML id
323+
* besides the input field
324+
* @param bool|null $userPrefsAllow whether user preferences are enabled
325+
* for this field (null - no support,
326+
* true/false - enabled/disabled)
327+
* @param array $jsDefault array which stores JavaScript code
328+
* to be displayed
331329
*
332330
* @return string|null HTML for input field
333331
*/
@@ -337,7 +335,6 @@ private function displayFieldInput(
337335
$systemPath,
338336
$workPath,
339337
$translatedPath,
340-
$showRestoreDefault,
341338
$userPrefsAllow,
342339
array &$jsDefault
343340
) {
@@ -354,7 +351,7 @@ private function displayFieldInput(
354351

355352
$opts = [
356353
'doc' => $this->getDocLink($systemPath),
357-
'show_restore_default' => $showRestoreDefault,
354+
'show_restore_default' => true,
358355
'userprefs_allow' => $userPrefsAllow,
359356
'userprefs_comment' => Descriptions::get($systemPath, 'cmt'),
360357
];

libraries/classes/Controllers/Database/StructureController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,6 @@ protected function getStuffForEngineTypeTable(
729729
// Merge or BerkleyDB table: Only row count is accurate.
730730
if ($this->isShowStats) {
731731
$formattedSize = ' - ';
732-
$unit = '';
733732
}
734733

735734
break;
@@ -754,7 +753,6 @@ protected function getStuffForEngineTypeTable(
754753
// Unknown table type.
755754
if ($this->isShowStats) {
756755
$formattedSize = __('unknown');
757-
$unit = '';
758756
}
759757
}
760758

@@ -816,7 +814,7 @@ protected function getValuesForAriaTable(
816814
[$formattedOverhead, $overheadUnit] = Util::formatByteDown(
817815
$currentTable['Data_free'],
818816
3,
819-
($currentTable['Data_free'] > 0 ? 1 : 0)
817+
1
820818
);
821819
$overheadSize += $currentTable['Data_free'];
822820
}

libraries/classes/Controllers/ErrorReportController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function __invoke(ServerRequest $request): void
9292
$success = false;
9393
} else {
9494
$decoded_response = json_decode($server_response, true);
95-
$success = ! empty($decoded_response) ? $decoded_response['success'] : false;
95+
$success = ! empty($decoded_response) && $decoded_response['success'];
9696
}
9797

9898
/* Message to show to the user */

libraries/classes/Controllers/Import/ImportController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public function __invoke(ServerRequest $request): void
519519

520520
return;
521521
}
522-
} elseif (! $GLOBALS['error'] && (! isset($GLOBALS['import_text']) || empty($GLOBALS['import_text']))) {
522+
} elseif (! $GLOBALS['error'] && (empty($GLOBALS['import_text']))) {
523523
$GLOBALS['message'] = Message::error(
524524
__(
525525
'No data was received to import. Either no file name was ' .

libraries/classes/Controllers/NavigationController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public function __invoke(ServerRequest $request): void
4949
return;
5050
}
5151

52-
$getNaviSettings = $request->getParsedBodyParam('getNaviSettings');
53-
if ($getNaviSettings !== null && $getNaviSettings) {
52+
if ($request->hasBodyParam('getNaviSettings')) {
5453
$pageSettings = new PageSettings('Navi', 'pma_navigation_settings');
5554
$this->response->addHTML($pageSettings->getErrorHTML());
5655
$this->response->addJSON('message', $pageSettings->getHTML());

libraries/classes/Controllers/Server/DatabasesController.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ class DatabasesController extends AbstractController
4646
/** @var bool whether to show database statistics */
4747
private $hasStatistics;
4848

49-
/** @var int position in list navigation */
50-
private $position;
51-
5249
private DatabaseInterface $dbi;
5350

5451
public function __construct(
@@ -93,7 +90,7 @@ public function __invoke(ServerRequest $request): void
9390

9491
$this->setSortDetails($params['sort_by'], $params['sort_order']);
9592
$this->hasStatistics = ! empty($params['statistics']);
96-
$this->position = ! empty($params['pos']) ? (int) $params['pos'] : 0;
93+
$position = ! empty($params['pos']) ? (int) $params['pos'] : 0;
9794

9895
/**
9996
* Gets the databases list
@@ -105,15 +102,15 @@ public function __invoke(ServerRequest $request): void
105102
Connection::TYPE_USER,
106103
$this->sortBy,
107104
$this->sortOrder,
108-
$this->position,
105+
$position,
109106
true
110107
);
111108
$this->databaseCount = count($this->dbi->getDatabaseList());
112109
}
113110

114111
$urlParams = [
115112
'statistics' => $this->hasStatistics,
116-
'pos' => $this->position,
113+
'pos' => $position,
117114
'sort_by' => $this->sortBy,
118115
'sort_order' => $this->sortOrder,
119116
];
@@ -155,7 +152,7 @@ public function __invoke(ServerRequest $request): void
155152
'header_statistics' => $headerStatistics,
156153
'charsets' => $charsetsList,
157154
'database_count' => $this->databaseCount,
158-
'pos' => $this->position,
155+
'pos' => $position,
159156
'url_params' => $urlParams,
160157
'max_db_list' => $GLOBALS['cfg']['MaxDbList'],
161158
'has_primary_replication' => $primaryInfo['status'],

libraries/classes/Controllers/Table/ChartController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function __invoke(ServerRequest $request): void
159159
'url_params' => $url_params,
160160
'keys' => $keys,
161161
'fields_meta' => $fields_meta,
162-
'table_has_a_numeric_column' => $numericColumnFound,
162+
'table_has_a_numeric_column' => true,
163163
'start_and_number_of_rows_fieldset' => $startAndNumberOfRowsFieldset,
164164
]);
165165
}

libraries/classes/Controllers/Table/Structure/SaveController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ private function updateColumns(): bool
119119
}
120120

121121
if (
122-
! isset($_POST['field_adjust_privileges'][$i])
123-
|| empty($_POST['field_adjust_privileges'][$i])
122+
empty($_POST['field_adjust_privileges'][$i])
124123
|| $_POST['field_orig'][$i] == $_POST['field_name'][$i]
125124
) {
126125
continue;
@@ -256,7 +255,7 @@ private function updateColumns(): bool
256255

257256
$revert_query = 'ALTER TABLE ' . Util::backquote($GLOBALS['table'])
258257
. ' ';
259-
$revert_query .= implode(', ', $changes_revert) . '';
258+
$revert_query .= implode(', ', $changes_revert);
260259
$revert_query .= ';';
261260

262261
// Column reverted back to original

libraries/classes/CreateAddField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public function getTableCreationQuery(string $db, string $table): string
406406
}
407407

408408
if (! empty($_POST['tbl_collation'])) {
409-
$sqlQuery .= Util::getCharsetQueryPart($_POST['tbl_collation'] ?? '');
409+
$sqlQuery .= Util::getCharsetQueryPart($_POST['tbl_collation']);
410410
}
411411

412412
if (

0 commit comments

Comments
 (0)