Skip to content

Commit 0e0a16b

Browse files
Merge pull request #18849 from MauricioFauth/db-table-global
Replace db and table globals with static class properties
2 parents 5abc1a5 + 48ea425 commit 0e0a16b

274 files changed

Lines changed: 1530 additions & 3467 deletions

File tree

Some content is hidden

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

phpstan-baseline.neon

Lines changed: 86 additions & 2306 deletions
Large diffs are not rendered by default.

psalm-baseline.xml

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,9 @@
14981498
<code>$favoriteTables</code>
14991499
<code>$favoriteTables</code>
15001500
</MixedArgument>
1501+
<MixedArgumentTypeCoercion>
1502+
<code><![CDATA[['db' => Current::$database]]]></code>
1503+
</MixedArgumentTypeCoercion>
15011504
<MixedArrayAccess>
15021505
<code><![CDATA[$value['db']]]></code>
15031506
<code><![CDATA[$value['table']]]></code>
@@ -1513,6 +1516,9 @@
15131516
<code>$favoriteTables</code>
15141517
<code>$value</code>
15151518
</MixedAssignment>
1519+
<MixedOperand>
1520+
<code>Current::$database</code>
1521+
</MixedOperand>
15161522
</file>
15171523
<file src="src/Controllers/Database/Structure/RealRowCountController.php">
15181524
<DeprecatedMethod>
@@ -2019,9 +2025,9 @@
20192025
<code><![CDATA[$GLOBALS['language_stats'][$GLOBALS['lang']]]]></code>
20202026
</MixedArrayAccess>
20212027
<MixedAssignment>
2022-
<code><![CDATA[$GLOBALS['db']]]></code>
20232028
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
20242029
<code><![CDATA[$GLOBALS['show_query']]]></code>
2030+
<code>Current::$database</code>
20252031
</MixedAssignment>
20262032
<PossiblyNullArgument>
20272033
<code><![CDATA[$this->config->get('TempDir')]]></code>
@@ -2077,9 +2083,11 @@
20772083
<code><![CDATA[$request->getParsedBodyParam('bkm_label')]]></code>
20782084
<code><![CDATA[$request->getParsedBodyParam('sql_query')]]></code>
20792085
<code><![CDATA[$request->getParsedBodyParam('sql_query')]]></code>
2086+
<code>Current::$table</code>
20802087
</MixedArgument>
20812088
<MixedArgumentTypeCoercion>
20822089
<code><![CDATA[$GLOBALS['urlParams']]]></code>
2090+
<code><![CDATA[$GLOBALS['urlParams']]]></code>
20832091
</MixedArgumentTypeCoercion>
20842092
<MixedArrayAccess>
20852093
<code><![CDATA[$_SESSION['Import_message']['go_back_url']]]></code>
@@ -2375,7 +2383,13 @@
23752383
</InvalidArrayOffset>
23762384
<MixedArgument>
23772385
<code><![CDATA[$request->getParsedBodyParam('comment')]]></code>
2386+
<code>Current::$database</code>
2387+
<code>Current::$database</code>
2388+
<code>Current::$database</code>
23782389
</MixedArgument>
2390+
<MixedArgumentTypeCoercion>
2391+
<code><![CDATA[['db' => Current::$database]]]></code>
2392+
</MixedArgumentTypeCoercion>
23792393
<MixedAssignment>
23802394
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
23812395
<code><![CDATA[$GLOBALS['single_table']]]></code>
@@ -3221,6 +3235,7 @@
32213235
<code><![CDATA[$GLOBALS['sql_query']]]></code>
32223236
<code><![CDATA[$request->getQueryParam('sql_signature')]]></code>
32233237
<code>$sqlQuery</code>
3238+
<code>Current::$table</code>
32243239
</MixedArgument>
32253240
<MixedArrayAccess>
32263241
<code><![CDATA[$GLOBALS['ajax_reload']['reload']]]></code>
@@ -3344,6 +3359,9 @@
33443359
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
33453360
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
33463361
</InvalidArrayOffset>
3362+
<MixedArgumentTypeCoercion>
3363+
<code><![CDATA[$GLOBALS['urlParams']]]></code>
3364+
</MixedArgumentTypeCoercion>
33473365
<MixedAssignment>
33483366
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
33493367
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
@@ -4278,7 +4296,11 @@
42784296
<code><![CDATA[$_REQUEST['item_name']]]></code>
42794297
</PossiblyInvalidCast>
42804298
<PossiblyNullArgument>
4281-
<code><![CDATA[$this->triggers->getTriggerByName($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['item_name'])]]></code>
4299+
<code><![CDATA[$this->triggers->getTriggerByName(
4300+
Current::$database,
4301+
Current::$table,
4302+
$_REQUEST['item_name'],
4303+
)]]></code>
42824304
</PossiblyNullArgument>
42834305
<PossiblyNullReference>
42844306
<code>isSuccess</code>
@@ -4794,7 +4816,7 @@
47944816
<code>$value</code>
47954817
</MixedAssignment>
47964818
<MixedOperand>
4797-
<code><![CDATA[$oneKey['ref_db_name'] ?? $GLOBALS['db']]]></code>
4819+
<code><![CDATA[$oneKey['ref_db_name'] ?? Current::$database]]></code>
47984820
<code><![CDATA[$oneKey['ref_table_name']]]></code>
47994821
<code><![CDATA[$value['foreign_db']]]></code>
48004822
<code><![CDATA[$value['foreign_table']]]></code>
@@ -5364,8 +5386,8 @@
53645386
<code><![CDATA[$expr->alias]]></code>
53655387
<code><![CDATA[$field->table]]></code>
53665388
<code>$newSortExpressionNoDirection</code>
5367-
<code><![CDATA[$oneKey['ref_db_name'] ?? $GLOBALS['db']]]></code>
5368-
<code><![CDATA[$oneKey['ref_db_name'] ?? $GLOBALS['db']]]></code>
5389+
<code><![CDATA[$oneKey['ref_db_name'] ?? Current::$database]]></code>
5390+
<code><![CDATA[$oneKey['ref_db_name'] ?? Current::$database]]></code>
53695391
<code><![CDATA[$oneKey['ref_index_list'][$index]]]></code>
53705392
<code><![CDATA[$oneKey['ref_table_name']]]></code>
53715393
<code><![CDATA[$oneKey['ref_table_name']]]></code>
@@ -6062,20 +6084,8 @@
60626084
<code>is_array($info) ? $info : []</code>
60636085
</MixedReturnTypeCoercion>
60646086
<RedundantCast>
6065-
<code><![CDATA[(string) $GLOBALS['db']]]></code>
6066-
<code><![CDATA[(string) $GLOBALS['table']]]></code>
60676087
<code><![CDATA[(string) $_REQUEST['no_history']]]></code>
60686088
</RedundantCast>
6069-
<RedundantCondition>
6070-
<code><![CDATA[is_scalar($GLOBALS['db'])]]></code>
6071-
<code><![CDATA[is_scalar($GLOBALS['table'])]]></code>
6072-
<code><![CDATA[isset($GLOBALS['db']) && is_scalar($GLOBALS['db'])]]></code>
6073-
<code><![CDATA[isset($GLOBALS['table']) && is_scalar($GLOBALS['table'])]]></code>
6074-
</RedundantCondition>
6075-
<TypeDoesNotContainType>
6076-
<code><![CDATA['']]></code>
6077-
<code><![CDATA['']]></code>
6078-
</TypeDoesNotContainType>
60796089
<UnusedReturnValue>
60806090
<code>mixed</code>
60816091
</UnusedReturnValue>
@@ -6496,10 +6506,13 @@
64966506
<MixedArgument>
64976507
<code><![CDATA[$GLOBALS['special_message']]]></code>
64986508
<code>$alt</code>
6509+
<code>$database</code>
6510+
<code>$database</code>
64996511
<code>$title</code>
65006512
</MixedArgument>
65016513
<MixedArgumentTypeCoercion>
65026514
<code>$key</code>
6515+
<code><![CDATA[['db' => $database]]]></code>
65036516
</MixedArgumentTypeCoercion>
65046517
<MixedArrayAssignment>
65056518
<code><![CDATA[$_SESSION['Import_message']['go_back_url']]]></code>
@@ -6509,6 +6522,7 @@
65096522
</MixedArrayAssignment>
65106523
<MixedAssignment>
65116524
<code>$alt</code>
6525+
<code>$database</code>
65126526
<code>$title</code>
65136527
<code>$value</code>
65146528
</MixedAssignment>
@@ -6523,9 +6537,6 @@
65236537
<PossiblyUndefinedArrayOffset>
65246538
<code>$parts[1]</code>
65256539
</PossiblyUndefinedArrayOffset>
6526-
<RedundantCast>
6527-
<code><![CDATA[(string) $GLOBALS['db']]]></code>
6528-
</RedundantCast>
65296540
<RiskyCast>
65306541
<code><![CDATA[$_REQUEST['pos']]]></code>
65316542
<code><![CDATA[$_REQUEST['session_max_rows']]]></code>
@@ -7192,6 +7203,9 @@
71927203
<code>$separator</code>
71937204
<code>$separator</code>
71947205
<code>$value</code>
7206+
<code>Current::$database</code>
7207+
<code>Current::$database</code>
7208+
<code>Current::$database</code>
71957209
</MixedArgument>
71967210
<MixedArrayAccess>
71977211
<code><![CDATA[$node->secondIcon['image']]]></code>
@@ -9126,9 +9140,6 @@
91269140
<PossiblyUnusedReturnValue>
91279141
<code>string[]</code>
91289142
</PossiblyUnusedReturnValue>
9129-
<RedundantCast>
9130-
<code><![CDATA[(string) $GLOBALS['db']]]></code>
9131-
</RedundantCast>
91329143
</file>
91339144
<file src="src/Plugins/Import/ImportLdi.php">
91349145
<DeprecatedMethod>
@@ -9358,9 +9369,6 @@
93589369
<PossiblyUnusedReturnValue>
93599370
<code>string[]</code>
93609371
</PossiblyUnusedReturnValue>
9361-
<RedundantCast>
9362-
<code><![CDATA[(string) $GLOBALS['db']]]></code>
9363-
</RedundantCast>
93649372
</file>
93659373
<file src="src/Plugins/Import/ImportSql.php">
93669374
<DeprecatedMethod>
@@ -10674,20 +10682,6 @@
1067410682
<MixedAssignment>
1067510683
<code>$value</code>
1067610684
</MixedAssignment>
10677-
<RedundantCast>
10678-
<code><![CDATA[(string) $GLOBALS['db']]]></code>
10679-
<code><![CDATA[(string) $GLOBALS['table']]]></code>
10680-
</RedundantCast>
10681-
<RedundantCondition>
10682-
<code><![CDATA[is_scalar($GLOBALS['db'])]]></code>
10683-
<code><![CDATA[is_scalar($GLOBALS['table'])]]></code>
10684-
<code><![CDATA[isset($GLOBALS['db']) && is_scalar($GLOBALS['db'])]]></code>
10685-
<code><![CDATA[isset($GLOBALS['table']) && is_scalar($GLOBALS['table'])]]></code>
10686-
</RedundantCondition>
10687-
<TypeDoesNotContainType>
10688-
<code><![CDATA['']]></code>
10689-
<code><![CDATA['']]></code>
10690-
</TypeDoesNotContainType>
1069110685
</file>
1069210686
<file src="src/Routing/Routing.php">
1069310687
<DeprecatedMethod>
@@ -11409,6 +11403,16 @@
1140911403
<code>Config::getInstance()</code>
1141011404
<code>Config::getInstance()</code>
1141111405
</DeprecatedMethod>
11406+
<MixedArgument>
11407+
<code>$table</code>
11408+
<code>Current::$table</code>
11409+
</MixedArgument>
11410+
<MixedArgumentTypeCoercion>
11411+
<code><![CDATA[['db' => $db, 'table' => $table]]]></code>
11412+
</MixedArgumentTypeCoercion>
11413+
<MixedAssignment>
11414+
<code>$table</code>
11415+
</MixedAssignment>
1141211416
<PossiblyInvalidArgument>
1141311417
<code>$query</code>
1141411418
</PossiblyInvalidArgument>
@@ -11994,11 +11998,11 @@
1199411998
<code>self::$trackingCache[$dbName][$tableName]</code>
1199511999
</MixedArrayAssignment>
1199612000
<MixedAssignment>
11997-
<code><![CDATA[$GLOBALS['db']]]></code>
1199812001
<code><![CDATA[$GLOBALS['export_type']]]></code>
1199912002
<code><![CDATA[$result['tablename']]]></code>
1200012003
<code>$trackingEnabled</code>
1200112004
<code>$trackingEnabled</code>
12005+
<code>Current::$database</code>
1200212006
</MixedAssignment>
1200312007
<MixedInferredReturnType>
1200412008
<code>bool</code>

psalm.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
csv_escaped: string,
5757
csv_separator: string,
5858
csv_terminated: string,
59-
db: string,
6059
db_priv: bool,
6160
dbs_to_test: string[]|false,
6261
display_query: string,
@@ -116,7 +115,6 @@
116115
sql_query: string,
117116
sql_structure_or_data: 'structure'|'data'|'structure_and_data',
118117
sql_type: 'INSERT'|'UPDATE'|'REPLACE',
119-
table: string,
120118
table_priv: bool,
121119
tbl_storage_engine: string,
122120
text_dir: string,

src/ConfigStorage/Relation.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpMyAdmin\Config;
88
use PhpMyAdmin\ConfigStorage\Features\PdfFeature;
9+
use PhpMyAdmin\Current;
910
use PhpMyAdmin\DatabaseInterface;
1011
use PhpMyAdmin\Dbal\Connection;
1112
use PhpMyAdmin\Identifiers\DatabaseName;
@@ -1378,7 +1379,7 @@ public function searchColumnInForeigners(array $foreigners, string $column): arr
13781379
$columnIndex = array_search($column, $oneKey['index_list']);
13791380
if ($columnIndex !== false) {
13801381
$foreigner['foreign_field'] = $oneKey['ref_index_list'][$columnIndex];
1381-
$foreigner['foreign_db'] = $oneKey['ref_db_name'] ?? $GLOBALS['db'];
1382+
$foreigner['foreign_db'] = $oneKey['ref_db_name'] ?? Current::$database;
13821383
$foreigner['foreign_table'] = $oneKey['ref_table_name'];
13831384
$foreigner['constraint'] = $oneKey['constraint'];
13841385
$foreigner['on_update'] = $oneKey['on_update'] ?? 'RESTRICT';
@@ -1689,7 +1690,7 @@ public function initRelationParamsCache(): void
16891690
return;
16901691
}
16911692

1692-
$this->fixPmaTables($GLOBALS['db'], false);
1693+
$this->fixPmaTables(Current::$database, false);
16931694
}
16941695

16951696
/**

src/Controllers/AbstractController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpMyAdmin\Controllers;
66

77
use Fig\Http\Message\StatusCodeInterface;
8+
use PhpMyAdmin\Current;
89
use PhpMyAdmin\Html\MySQLDocumentation;
910
use PhpMyAdmin\Message;
1011
use PhpMyAdmin\ResponseRenderer;
@@ -57,6 +58,14 @@ protected function checkParameters(array $params, bool $request = false): bool
5758
continue;
5859
}
5960

61+
if (! $request && $param === 'db' && Current::$database !== '') {
62+
continue;
63+
}
64+
65+
if (! $request && $param === 'table' && Current::$table !== '') {
66+
continue;
67+
}
68+
6069
$errorMessage .=
6170
__('Missing parameter:') . ' '
6271
. $param

src/Controllers/CheckRelationsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpMyAdmin\Config;
88
use PhpMyAdmin\ConfigStorage\Relation;
9+
use PhpMyAdmin\Current;
910
use PhpMyAdmin\Http\ServerRequest;
1011
use PhpMyAdmin\Identifiers\DatabaseName;
1112
use PhpMyAdmin\ResponseRenderer;
@@ -27,7 +28,7 @@ public function __invoke(ServerRequest $request): void
2728
{
2829
$cfgStorageDbName = $this->relation->getConfigurationStorageDbName();
2930

30-
$db = DatabaseName::tryFrom($GLOBALS['db']);
31+
$db = DatabaseName::tryFrom(Current::$database);
3132

3233
// If request for creating the pmadb
3334
if ($request->hasBodyParam('create_pmadb') && $this->relation->createPmaDatabase($cfgStorageDbName)) {

src/Controllers/Database/CentralColumns/PopulateColumnsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpMyAdmin\Controllers\Database\CentralColumns;
66

77
use PhpMyAdmin\Controllers\AbstractController;
8+
use PhpMyAdmin\Current;
89
use PhpMyAdmin\Database\CentralColumns;
910
use PhpMyAdmin\Http\ServerRequest;
1011
use PhpMyAdmin\ResponseRenderer;
@@ -23,7 +24,7 @@ public function __construct(
2324
public function __invoke(ServerRequest $request): void
2425
{
2526
$columns = $this->centralColumns->getColumnsNotInCentralList(
26-
$GLOBALS['db'],
27+
Current::$database,
2728
$request->getParsedBodyParam('selectedTable'),
2829
);
2930
$this->render('database/central_columns/populate_columns', ['columns' => $columns]);

0 commit comments

Comments
 (0)