Skip to content

Commit 6264f6f

Browse files
Various refactorings 2 (#17965)
* Remove extra blank lines * Remove useless param annotations * Refactor Index::singleton * Refactor Config.php * Refactor Header::addRecentTable() * Collapse return statement into a single line * Refactor Message.php * Convert $getUniqueCondition into a scalar * Code style * Fix invalid return phpdoc * Remove unused variable * Remove redundant empty array checks * Refactor Export::closeFile() * Simplify else statement * Remove redundant else * Refactor TablePartitionDefinition::getDetails * Simpler returns * Add types for getCellContent() * Remove useless method mngInsideStructComm Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
1 parent e5e070c commit 6264f6f

42 files changed

Lines changed: 163 additions & 284 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/Advisory/Advisor.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ class Advisor
4646
*/
4747
private $rules = [];
4848

49-
/** @var array */
50-
private $runResult;
49+
/** @var array{fired:array, notfired:array, unchecked:array, errors:array} */
50+
private $runResult = [
51+
'fired' => [],
52+
'notfired' => [],
53+
'unchecked' => [],
54+
'errors' => [],
55+
];
5156

5257
/** @var ExpressionLanguage */
5358
private $expression;
@@ -151,10 +156,6 @@ static function (): void {
151156
* @param int $value
152157
*/
153158
function ($arguments, $value) {
154-
if (! isset($this->runResult['fired'])) {
155-
return 0;
156-
}
157-
158159
// Did matching rule fire?
159160
foreach ($this->runResult['fired'] as $rule) {
160161
if ($rule['id'] == $value) {
@@ -209,15 +210,15 @@ private function setRules(): void
209210
}
210211

211212
/**
212-
* @return array
213+
* @return array{fired: array, notfired: array, unchecked: array, errors: array}
213214
*/
214215
public function getRunResult(): array
215216
{
216217
return $this->runResult;
217218
}
218219

219220
/**
220-
* @return array
221+
* @psalm-return array{fired:array, notfired:array, unchecked:array, errors:array}
221222
*/
222223
public function run(): array
223224
{
@@ -317,6 +318,7 @@ private function runRules(): void
317318
*
318319
* @param string $type type of rule
319320
* @param array $rule rule itself
321+
* @psalm-param 'notfired'|'fired'|'unchecked'|'errors' $type
320322
*/
321323
public function addRule(string $type, array $rule): void
322324
{

libraries/classes/BrowseForeigners.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,17 +296,16 @@ private function getDescriptionAndTitle(string $description): array
296296
*/
297297
private function getHtmlForGotoPage(?array $foreignData): string
298298
{
299-
$gotoPage = '';
300299
isset($_POST['pos']) ? $pos = $_POST['pos'] : $pos = 0;
301300
if ($foreignData === null || ! is_array($foreignData['disp_row'])) {
302-
return $gotoPage;
301+
return '';
303302
}
304303

305304
$pageNow = (int) floor($pos / $this->maxRows) + 1;
306305
$nbTotalPage = (int) ceil($foreignData['the_total'] / $this->maxRows);
307306

308307
if ($foreignData['the_total'] > $this->maxRows) {
309-
$gotoPage = Util::pageselector(
308+
return Util::pageselector(
310309
'pos',
311310
$this->maxRows,
312311
$pageNow,
@@ -320,7 +319,7 @@ private function getHtmlForGotoPage(?array $foreignData): string
320319
);
321320
}
322321

323-
return $gotoPage;
322+
return '';
324323
}
325324

326325
/**

libraries/classes/Config.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
use function str_contains;
5353
use function str_replace;
5454
use function stripos;
55-
use function strlen;
5655
use function strtolower;
5756
use function substr;
5857
use function sys_get_temp_dir;
@@ -712,11 +711,7 @@ public function checkErrors(): void
712711
*/
713712
public function get(string $setting)
714713
{
715-
if (isset($this->settings[$setting])) {
716-
return $this->settings[$setting];
717-
}
718-
719-
return null;
714+
return $this->settings[$setting] ?? null;
720715
}
721716

722717
/**
@@ -926,7 +921,7 @@ public function setCookie(
926921
?int $validity = null,
927922
bool $httponly = true
928923
): bool {
929-
if (strlen($value) > 0 && $default !== null && $value === $default) {
924+
if ($value !== '' && $value === $default) {
930925
// default value is used
931926
if ($this->issetCookie($cookie)) {
932927
// remove cookie
@@ -936,7 +931,7 @@ public function setCookie(
936931
return false;
937932
}
938933

939-
if (strlen($value) === 0 && $this->issetCookie($cookie)) {
934+
if ($value === '' && $this->issetCookie($cookie)) {
940935
// remove cookie, value is empty
941936
return $this->removeCookie($cookie);
942937
}
@@ -1002,11 +997,7 @@ public function setCookie(
1002997
*/
1003998
public function getCookie(string $cookieName)
1004999
{
1005-
if (isset($_COOKIE[$this->getCookieName($cookieName)])) {
1006-
return $_COOKIE[$this->getCookieName($cookieName)];
1007-
}
1008-
1009-
return null;
1000+
return $_COOKIE[$this->getCookieName($cookieName)] ?? null;
10101001
}
10111002

10121003
/**

libraries/classes/Controllers/Import/ImportController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,9 @@ public function __invoke(ServerRequest $request): void
385385
$this->response->addJSON('action_bookmark', $action_bookmark);
386386

387387
return;
388-
} else {
389-
$GLOBALS['run_query'] = false;
390388
}
391389

390+
$GLOBALS['run_query'] = false;
392391
break;
393392
case 2: // bookmarked query that have to be deleted
394393
$bookmark = Bookmark::get(
@@ -412,11 +411,10 @@ public function __invoke(ServerRequest $request): void
412411
$this->response->addJSON('id_bookmark', $id_bookmark);
413412

414413
return;
415-
} else {
416-
$GLOBALS['run_query'] = false;
417-
$GLOBALS['error'] = true; // this is kind of hack to skip processing the query
418414
}
419415

416+
$GLOBALS['run_query'] = false;
417+
$GLOBALS['error'] = true; // this is kind of hack to skip processing the query
420418
break;
421419
}
422420
}

libraries/classes/Controllers/Preferences/ManageController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ public function __invoke(ServerRequest $request): void
254254
$this->userPreferences->redirect('index.php?route=/preferences/manage', $GLOBALS['params']);
255255

256256
return;
257-
} else {
258-
$GLOBALS['error'] = $result;
259257
}
260258

259+
$GLOBALS['error'] = $result;
260+
261261
return;
262262
}
263263

libraries/classes/Controllers/Table/RelationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function __invoke(ServerRequest $request): void
150150
: [];
151151
$i = 0;
152152

153-
foreach ($existrelForeign as $key => $oneKey) {
153+
foreach ($existrelForeign as $oneKey) {
154154
$foreignDb = $oneKey['ref_db_name'] ?? $GLOBALS['db'];
155155
$foreignTable = false;
156156
if ($foreignDb) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ public function __invoke(ServerRequest $request): void
7575

7676
$storageEngines = StorageEngine::getArray();
7777

78-
$partitionDetails = TablePartitionDefinition::getDetails($partitionDetails);
78+
if ($partitionDetails === null) {
79+
$partitionDetails = TablePartitionDefinition::getDetails();
80+
}
81+
7982
$this->render('table/structure/partition_definition_form', [
8083
'db' => $GLOBALS['db'],
8184
'table' => $GLOBALS['table'],

libraries/classes/Controllers/Table/ZoomSearchController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,21 @@ public function zoomSubmitAction($dataLabel, $goto): void
346346
$tmpRow = array_values($row);
347347

348348
//Get unique condition on each row (will be needed for row update)
349-
$uniqueCondition = Util::getUniqueCondition(
349+
[$uniqueCondition] = Util::getUniqueCondition(
350350
count($this->columnNames),
351351
$fields_meta,
352352
$tmpRow,
353353
true
354354
);
355355
//Append it to row array as where_clause
356-
$row['where_clause'] = $uniqueCondition[0];
357-
$row['where_clause_sign'] = Core::signSqlQuery($uniqueCondition[0]);
356+
$row['where_clause'] = $uniqueCondition;
357+
$row['where_clause_sign'] = Core::signSqlQuery($uniqueCondition);
358358

359359
$tmpData = [
360360
$_POST['criteriaColumnNames'][0] => $row[$_POST['criteriaColumnNames'][0]],
361361
$_POST['criteriaColumnNames'][1] => $row[$_POST['criteriaColumnNames'][1]],
362-
'where_clause' => $uniqueCondition[0],
363-
'where_clause_sign' => Core::signSqlQuery($uniqueCondition[0]),
362+
'where_clause' => $uniqueCondition,
363+
'where_clause_sign' => Core::signSqlQuery($uniqueCondition),
364364
];
365365
$tmpData[$dataLabel] = $dataLabel ? $row[$dataLabel] : '';
366366
$data[] = $tmpData;

libraries/classes/Core.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ public static function populateRequestWithEncryptedQueryParams(ServerRequest $re
900900
if ($decryptedQuery === null) {
901901
$request = $request->withQueryParams($queryParams);
902902
if (is_array($parsedBody)) {
903-
$request = $request->withParsedBody($parsedBody);
903+
return $request->withParsedBody($parsedBody);
904904
}
905905

906906
return $request;
@@ -921,7 +921,7 @@ public static function populateRequestWithEncryptedQueryParams(ServerRequest $re
921921

922922
$request = $request->withQueryParams($queryParams);
923923
if (is_array($parsedBody)) {
924-
$request = $request->withParsedBody($parsedBody);
924+
return $request->withParsedBody($parsedBody);
925925
}
926926

927927
return $request;

libraries/classes/Database/CentralColumns.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,13 @@ public function syncUniqueColumns(
361361
}
362362

363363
$this->dbi->selectDb($pmadb, DatabaseInterface::CONNECT_CONTROL);
364-
if (! empty($insQuery)) {
365-
foreach ($insQuery as $query) {
366-
if (! $this->dbi->tryQuery($query, DatabaseInterface::CONNECT_CONTROL)) {
367-
$message = Message::error(__('Could not add columns!'));
368-
$message->addMessage(
369-
Message::rawError($this->dbi->getError(DatabaseInterface::CONNECT_CONTROL))
370-
);
371-
break;
372-
}
364+
foreach ($insQuery as $query) {
365+
if (! $this->dbi->tryQuery($query, DatabaseInterface::CONNECT_CONTROL)) {
366+
$message = Message::error(__('Could not add columns!'));
367+
$message->addMessage(
368+
Message::rawError($this->dbi->getError(DatabaseInterface::CONNECT_CONTROL))
369+
);
370+
break;
373371
}
374372
}
375373

0 commit comments

Comments
 (0)