Skip to content

Commit fdf474a

Browse files
Merge pull request #17981 from kamil-tekiela/getTables-investigation
Improve some type inference in various places Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2 parents d5f3c91 + 70af3e9 commit fdf474a

20 files changed

Lines changed: 136 additions & 225 deletions

libraries/classes/Controllers/Database/DesignerController.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@ public function __construct(
3939

4040
public function __invoke(ServerRequest $request): void
4141
{
42-
$GLOBALS['script_display_field'] = $GLOBALS['script_display_field'] ?? null;
4342
$GLOBALS['tab_column'] = $GLOBALS['tab_column'] ?? null;
4443
$GLOBALS['tables_all_keys'] = $GLOBALS['tables_all_keys'] ?? null;
4544
$GLOBALS['tables_pk_or_unique_keys'] = $GLOBALS['tables_pk_or_unique_keys'] ?? null;
4645
$GLOBALS['success'] = $GLOBALS['success'] ?? null;
4746
$GLOBALS['page'] = $GLOBALS['page'] ?? null;
4847
$GLOBALS['message'] = $GLOBALS['message'] ?? null;
4948
$GLOBALS['selected_page'] = $GLOBALS['selected_page'] ?? null;
50-
$GLOBALS['tab_pos'] = $GLOBALS['tab_pos'] ?? null;
51-
$GLOBALS['fullTableNames'] = $GLOBALS['fullTableNames'] ?? null;
5249
$GLOBALS['script_tables'] = $GLOBALS['script_tables'] ?? null;
5350
$GLOBALS['script_contr'] = $GLOBALS['script_contr'] ?? null;
5451
$GLOBALS['params'] = $GLOBALS['params'] ?? null;
@@ -72,16 +69,16 @@ public function __invoke(ServerRequest $request): void
7269
$html = $this->databaseDesigner->getHtmlForSchemaExport($_POST['db'], $_POST['selected_page']);
7370
} elseif ($_POST['dialog'] === 'add_table') {
7471
// Pass the db and table to the getTablesInfo so we only have the table we asked for
75-
$GLOBALS['script_display_field'] = $this->designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
76-
$GLOBALS['tab_column'] = $this->designerCommon->getColumnsInfo($GLOBALS['script_display_field']);
77-
$GLOBALS['tables_all_keys'] = $this->designerCommon->getAllKeys($GLOBALS['script_display_field']);
72+
$scriptDisplayField = $this->designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
73+
$GLOBALS['tab_column'] = $this->designerCommon->getColumnsInfo($scriptDisplayField);
74+
$GLOBALS['tables_all_keys'] = $this->designerCommon->getAllKeys($scriptDisplayField);
7875
$GLOBALS['tables_pk_or_unique_keys'] = $this->designerCommon->getPkOrUniqueKeys(
79-
$GLOBALS['script_display_field']
76+
$scriptDisplayField
8077
);
8178

8279
$html = $this->databaseDesigner->getDatabaseTables(
8380
$_POST['db'],
84-
$GLOBALS['script_display_field'],
81+
$scriptDisplayField,
8582
[],
8683
-1,
8784
$GLOBALS['tab_column'],
@@ -170,7 +167,7 @@ public function __invoke(ServerRequest $request): void
170167
return;
171168
}
172169

173-
$GLOBALS['script_display_field'] = $this->designerCommon->getTablesInfo();
170+
$scriptDisplayField = $this->designerCommon->getTablesInfo();
174171

175172
$GLOBALS['selected_page'] = null;
176173

@@ -188,34 +185,33 @@ public function __invoke(ServerRequest $request): void
188185
$GLOBALS['selected_page'] = $this->designerCommon->getPageName($displayPage);
189186
}
190187

191-
$GLOBALS['tab_pos'] = $this->designerCommon->getTablePositions($displayPage);
188+
$tablePositions = $this->designerCommon->getTablePositions($displayPage);
192189

193-
$GLOBALS['fullTableNames'] = [];
194-
195-
foreach ($GLOBALS['script_display_field'] as $designerTable) {
196-
$GLOBALS['fullTableNames'][] = $designerTable->getDbTableString();
190+
$fullTableNames = [];
191+
foreach ($scriptDisplayField as $designerTable) {
192+
$fullTableNames[] = $designerTable->getDbTableString();
197193
}
198194

199-
foreach ($GLOBALS['tab_pos'] as $position) {
200-
if (in_array($position['dbName'] . '.' . $position['tableName'], $GLOBALS['fullTableNames'])) {
195+
foreach ($tablePositions as $position) {
196+
if (in_array($position['dbName'] . '.' . $position['tableName'], $fullTableNames)) {
201197
continue;
202198
}
203199

204200
$designerTables = $this->designerCommon->getTablesInfo($position['dbName'], $position['tableName']);
205201
foreach ($designerTables as $designerTable) {
206-
$GLOBALS['script_display_field'][] = $designerTable;
202+
$scriptDisplayField[] = $designerTable;
207203
}
208204
}
209205

210-
$GLOBALS['tab_column'] = $this->designerCommon->getColumnsInfo($GLOBALS['script_display_field']);
211-
$GLOBALS['script_tables'] = $this->designerCommon->getScriptTabs($GLOBALS['script_display_field']);
206+
$GLOBALS['tab_column'] = $this->designerCommon->getColumnsInfo($scriptDisplayField);
207+
$GLOBALS['script_tables'] = $this->designerCommon->getScriptTabs($scriptDisplayField);
212208
$GLOBALS['tables_pk_or_unique_keys'] = $this->designerCommon->getPkOrUniqueKeys(
213-
$GLOBALS['script_display_field']
209+
$scriptDisplayField
214210
);
215-
$GLOBALS['tables_all_keys'] = $this->designerCommon->getAllKeys($GLOBALS['script_display_field']);
211+
$GLOBALS['tables_all_keys'] = $this->designerCommon->getAllKeys($scriptDisplayField);
216212
$GLOBALS['classes_side_menu'] = $this->databaseDesigner->returnClassNamesFromMenuButtons();
217213

218-
$GLOBALS['script_contr'] = $this->designerCommon->getScriptContr($GLOBALS['script_display_field']);
214+
$GLOBALS['script_contr'] = $this->designerCommon->getScriptContr($scriptDisplayField);
219215

220216
$GLOBALS['params'] = ['lang' => $GLOBALS['lang']];
221217
if (isset($_GET['db'])) {
@@ -250,15 +246,15 @@ public function __invoke(ServerRequest $request): void
250246
$this->databaseDesigner->getHtmlForMain(
251247
$GLOBALS['db'],
252248
$_GET['db'],
253-
$GLOBALS['script_display_field'],
249+
$scriptDisplayField,
254250
$GLOBALS['script_tables'],
255251
$GLOBALS['script_contr'],
256-
$GLOBALS['script_display_field'],
252+
$scriptDisplayField,
257253
$displayPage,
258254
$visualBuilderMode,
259255
$GLOBALS['selected_page'],
260256
$GLOBALS['classes_side_menu'],
261-
$GLOBALS['tab_pos'],
257+
$tablePositions,
262258
$GLOBALS['tab_column'],
263259
$GLOBALS['tables_all_keys'],
264260
$GLOBALS['tables_pk_or_unique_keys']

libraries/classes/Controllers/Server/VariablesController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ public function __invoke(ServerRequest $request): void
5050
$variables = [];
5151
$serverVarsResult = $this->dbi->tryQuery('SHOW SESSION VARIABLES;');
5252
if ($serverVarsResult !== false) {
53+
/** @var array<string, string> $serverVarsSession */
5354
$serverVarsSession = $serverVarsResult->fetchAllKeyPair();
5455

5556
unset($serverVarsResult);
5657

58+
/** @var array<string, string> $serverVars */
5759
$serverVars = $this->dbi->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1);
5860

5961
// list of static (i.e. non-editable) system variables

libraries/classes/Database/Designer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function getDatabaseTables(
312312
* @param bool $visualBuilderMode whether this is visual query builder
313313
* @param string $selectedPage name of the selected page
314314
* @param array $paramsArray array with class name for various buttons on side menu
315-
* @param array|null $tabPos table positions
315+
* @param array $tablePositions table positions
316316
* @param array $tabColumn table column info
317317
* @param array $tablesAllKeys all indices
318318
* @param array $tablesPkOrUniqueKeys unique or primary indices
@@ -330,7 +330,7 @@ public function getHtmlForMain(
330330
bool $visualBuilderMode,
331331
$selectedPage,
332332
array $paramsArray,
333-
?array $tabPos,
333+
array $tablePositions,
334334
array $tabColumn,
335335
array $tablesAllKeys,
336336
array $tablesPkOrUniqueKeys
@@ -399,7 +399,7 @@ public function getHtmlForMain(
399399
'visual_builder' => $visualBuilderMode,
400400
'selected_page' => $selectedPage,
401401
'params_array' => $paramsArray,
402-
'tab_pos' => $tabPos,
402+
'tab_pos' => $tablePositions,
403403
'tab_column' => $tabColumn,
404404
'tables_all_keys' => $tablesAllKeys,
405405
'tables_pk_or_unique_keys' => $tablesPkOrUniqueKeys,

libraries/classes/Database/Designer/Common.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ public function getScriptTabs(array $designerTables): array
264264
*
265265
* @param int $pg pdf page id
266266
*
267-
* @return array|null of table positions
267+
* @return array of table positions
268268
*/
269-
public function getTablePositions(int $pg): ?array
269+
public function getTablePositions(int $pg): array
270270
{
271271
$pdfFeature = $this->relation->getRelationParameters()->pdfFeature;
272272
if ($pdfFeature === null) {
@@ -310,14 +310,13 @@ public function getPageName(int $pg)
310310
. ' FROM ' . Util::backquote($pdfFeature->database)
311311
. '.' . Util::backquote($pdfFeature->pdfPages)
312312
. ' WHERE ' . Util::backquote('page_nr') . ' = ' . intval($pg);
313-
$page_name = $this->dbi->fetchResult(
313+
$page_name = $this->dbi->fetchValue(
314314
$query,
315-
null,
316-
null,
315+
0,
317316
DatabaseInterface::CONNECT_CONTROL
318317
);
319318

320-
return $page_name[0] ?? null;
319+
return $page_name !== false ? $page_name : null;
321320
}
322321

323322
/**
@@ -366,18 +365,13 @@ public function getDefaultPage($db): int
366365
. " WHERE `db_name` = '" . $this->dbi->escapeString($db) . "'"
367366
. " AND `page_descr` = '" . $this->dbi->escapeString($db) . "'";
368367

369-
$default_page_no = $this->dbi->fetchResult(
368+
$default_page_no = $this->dbi->fetchValue(
370369
$query,
371-
null,
372-
null,
370+
0,
373371
DatabaseInterface::CONNECT_CONTROL
374372
);
375373

376-
if (isset($default_page_no[0])) {
377-
return intval($default_page_no[0]);
378-
}
379-
380-
return -1;
374+
return is_string($default_page_no) ? intval($default_page_no) : -1;
381375
}
382376

383377
/**
@@ -404,7 +398,7 @@ public function getPageExists(string $pg): bool
404398
DatabaseInterface::CONNECT_CONTROL
405399
);
406400

407-
return count($pageNos) > 0;
401+
return $pageNos !== [];
408402
}
409403

410404
/**
@@ -432,15 +426,13 @@ public function getLoadingPage($db)
432426
. '.' . Util::backquote($pdfFeature->pdfPages)
433427
. " WHERE `db_name` = '" . $this->dbi->escapeString($db) . "'";
434428

435-
$min_page_no = $this->dbi->fetchResult(
429+
$min_page_no = $this->dbi->fetchValue(
436430
$query,
437-
null,
438-
null,
431+
0,
439432
DatabaseInterface::CONNECT_CONTROL
440433
);
441-
$page_no = $min_page_no[0] ?? -1;
442434

443-
return intval($page_no);
435+
return is_string($min_page_no) ? intval($min_page_no) : -1;
444436
}
445437

446438
/**

libraries/classes/Database/MultiTableQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MultiTableQuery
4949
/**
5050
* Table names
5151
*
52-
* @var array
52+
* @var array<int, string>
5353
*/
5454
private $tables;
5555

libraries/classes/DatabaseInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,15 @@ public function tryQueryAsControlUser(string $sql)
325325
* @param string $database name of database
326326
* @param int $link mysql link resource|object
327327
*
328-
* @return array tables names
328+
* @return array<int, string> tables names
329329
*/
330330
public function getTables(string $database, int $link = self::CONNECT_USER): array
331331
{
332332
if ($database === '') {
333333
return [];
334334
}
335335

336+
/** @var array<int, string> $tables */
336337
$tables = $this->fetchResult(
337338
'SHOW TABLES FROM ' . Util::backquote($database) . ';',
338339
null,

libraries/classes/Dbal/DbalInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function tryMultiQuery(
6767
* @param string $database name of database
6868
* @param int $link mysql link resource|object
6969
*
70-
* @return array tables names
70+
* @return array<int, string> tables names
7171
*/
7272
public function getTables(string $database, int $link = DatabaseInterface::CONNECT_USER): array;
7373

libraries/classes/Operations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ public function copyTables(array $tablesFull, $move, $db, DatabaseName $newDatab
252252
*/
253253
public function runEventDefinitionsForDb($db, DatabaseName $newDatabaseName): void
254254
{
255+
/** @var string[] $eventNames */
255256
$eventNames = $this->dbi->fetchResult(
256257
'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= '
257258
. $this->dbi->quoteString($db) . ';'

libraries/classes/Table.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,12 @@ public function isView(): bool
241241
}
242242

243243
// query information_schema
244-
$result = $this->dbi->fetchResult(
245-
'SELECT TABLE_NAME'
244+
return (bool) $this->dbi->fetchValue(
245+
'SELECT 1'
246246
. ' FROM information_schema.VIEWS'
247247
. ' WHERE TABLE_SCHEMA = ' . $this->dbi->quoteString($this->dbName)
248248
. ' AND TABLE_NAME = ' . $this->dbi->quoteString($this->name)
249249
);
250-
251-
return (bool) $result;
252250
}
253251

254252
/**
@@ -260,15 +258,13 @@ public function isUpdatableView(): bool
260258
return false;
261259
}
262260

263-
$result = $this->dbi->fetchResult(
264-
'SELECT TABLE_NAME'
261+
return (bool) $this->dbi->fetchValue(
262+
'SELECT 1'
265263
. ' FROM information_schema.VIEWS'
266264
. ' WHERE TABLE_SCHEMA = ' . $this->dbi->quoteString($this->dbName)
267265
. ' AND TABLE_NAME = ' . $this->dbi->quoteString($this->name)
268266
. ' AND IS_UPDATABLE = \'YES\''
269267
);
270-
271-
return (bool) $result;
272268
}
273269

274270
/**

phpstan-baseline.neon

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,11 +1735,6 @@ parameters:
17351735
count: 1
17361736
path: libraries/classes/Controllers/Server/VariablesController.php
17371737

1738-
-
1739-
message: "#^Parameter \\#2 \\$value of method PhpMyAdmin\\\\Controllers\\\\Server\\\\VariablesController\\:\\:formatVariable\\(\\) expects int\\|string, string\\|null given\\.$#"
1740-
count: 1
1741-
path: libraries/classes/Controllers/Server/VariablesController.php
1742-
17431738
-
17441739
message: "#^Method PhpMyAdmin\\\\Controllers\\\\Setup\\\\AbstractController\\:\\:getPages\\(\\) return type has no value type specified in iterable type array\\.$#"
17451740
count: 1
@@ -2286,7 +2281,7 @@ parameters:
22862281
path: libraries/classes/Database/Designer.php
22872282

22882283
-
2289-
message: "#^Method PhpMyAdmin\\\\Database\\\\Designer\\:\\:getHtmlForMain\\(\\) has parameter \\$tabPos with no value type specified in iterable type array\\.$#"
2284+
message: "#^Method PhpMyAdmin\\\\Database\\\\Designer\\:\\:getHtmlForMain\\(\\) has parameter \\$tablePositions with no value type specified in iterable type array\\.$#"
22902285
count: 1
22912286
path: libraries/classes/Database/Designer.php
22922287

@@ -2405,11 +2400,6 @@ parameters:
24052400
count: 1
24062401
path: libraries/classes/Database/Events.php
24072402

2408-
-
2409-
message: "#^Property PhpMyAdmin\\\\Database\\\\MultiTableQuery\\:\\:\\$tables type has no value type specified in iterable type array\\.$#"
2410-
count: 1
2411-
path: libraries/classes/Database/MultiTableQuery.php
2412-
24132403
-
24142404
message: "#^Casting to string something that's already string\\.$#"
24152405
count: 1
@@ -2990,11 +2980,6 @@ parameters:
29902980
count: 1
29912981
path: libraries/classes/DatabaseInterface.php
29922982

2993-
-
2994-
message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getTables\\(\\) return type has no value type specified in iterable type array\\.$#"
2995-
count: 1
2996-
path: libraries/classes/DatabaseInterface.php
2997-
29982983
-
29992984
message: "#^Method PhpMyAdmin\\\\DatabaseInterface\\:\\:getTablesFull\\(\\) has parameter \\$table with no value type specified in iterable type array\\.$#"
30002985
count: 1
@@ -3075,11 +3060,6 @@ parameters:
30753060
count: 1
30763061
path: libraries/classes/Dbal/DbalInterface.php
30773062

3078-
-
3079-
message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getTables\\(\\) return type has no value type specified in iterable type array\\.$#"
3080-
count: 1
3081-
path: libraries/classes/Dbal/DbalInterface.php
3082-
30833063
-
30843064
message: "#^Method PhpMyAdmin\\\\Dbal\\\\DbalInterface\\:\\:getTablesFull\\(\\) has parameter \\$table with no value type specified in iterable type array\\.$#"
30853065
count: 1

0 commit comments

Comments
 (0)