Skip to content

Commit 98b0d33

Browse files
Merge pull request #19519 from MauricioFauth/plugins-globals-removal
Remove plugin global variables
2 parents e7c1114 + 3a619b6 commit 98b0d33

22 files changed

Lines changed: 228 additions & 186 deletions

phpstan-baseline.neon

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ parameters:
21152115
Use dependency injection instead\.$#
21162116
'''
21172117
identifier: staticMethod.deprecated
2118-
count: 1
2118+
count: 3
21192119
path: src/Controllers/Database/ImportController.php
21202120

21212121
-
@@ -2136,12 +2136,6 @@ parameters:
21362136
count: 1
21372137
path: src/Controllers/Database/ImportController.php
21382138

2139-
-
2140-
message: '#^Cannot cast mixed to string\.$#'
2141-
identifier: cast.string
2142-
count: 1
2143-
path: src/Controllers/Database/ImportController.php
2144-
21452139
-
21462140
message: '#^Parameter \#2 \$db of static method PhpMyAdmin\\Database\\MultiTableQuery\:\:displayResults\(\) expects string, mixed given\.$#'
21472141
identifier: argument.type
@@ -3369,7 +3363,7 @@ parameters:
33693363
Use dependency injection instead\.$#
33703364
'''
33713365
identifier: staticMethod.deprecated
3372-
count: 1
3366+
count: 3
33733367
path: src/Controllers/Server/ImportController.php
33743368

33753369
-
@@ -3390,12 +3384,6 @@ parameters:
33903384
count: 1
33913385
path: src/Controllers/Server/ImportController.php
33923386

3393-
-
3394-
message: '#^Cannot cast mixed to string\.$#'
3395-
identifier: cast.string
3396-
count: 1
3397-
path: src/Controllers/Server/ImportController.php
3398-
33993387
-
34003388
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
34013389
identifier: empty.notAllowed
@@ -4071,7 +4059,7 @@ parameters:
40714059
Use dependency injection instead\.$#
40724060
'''
40734061
identifier: staticMethod.deprecated
4074-
count: 1
4062+
count: 3
40754063
path: src/Controllers/Table/ImportController.php
40764064

40774065
-
@@ -4092,12 +4080,6 @@ parameters:
40924080
count: 1
40934081
path: src/Controllers/Table/ImportController.php
40944082

4095-
-
4096-
message: '#^Cannot cast mixed to string\.$#'
4097-
identifier: cast.string
4098-
count: 1
4099-
path: src/Controllers/Table/ImportController.php
4100-
41014083
-
41024084
message: '#^Binary operation "\+\=" between int and mixed results in an error\.$#'
41034085
identifier: assignOp.invalid
@@ -5745,13 +5727,7 @@ parameters:
57455727
Use dependency injection instead\.$#
57465728
'''
57475729
identifier: staticMethod.deprecated
5748-
count: 1
5749-
path: src/Database/Designer.php
5750-
5751-
-
5752-
message: '#^Cannot cast mixed to string\.$#'
5753-
identifier: cast.string
5754-
count: 1
5730+
count: 2
57555731
path: src/Database/Designer.php
57565732

57575733
-
@@ -7494,7 +7470,7 @@ parameters:
74947470
Use dependency injection instead\.$#
74957471
'''
74967472
identifier: staticMethod.deprecated
7497-
count: 3
7473+
count: 4
74987474
path: src/Export/Options.php
74997475

75007476
-
@@ -7521,7 +7497,7 @@ parameters:
75217497
-
75227498
message: '#^Cannot cast mixed to string\.$#'
75237499
identifier: cast.string
7524-
count: 4
7500+
count: 3
75257501
path: src/Export/Options.php
75267502

75277503
-
@@ -10515,6 +10491,12 @@ parameters:
1051510491
count: 1
1051610492
path: src/Plugins.php
1051710493

10494+
-
10495+
message: '#^Cannot cast mixed to string\.$#'
10496+
identifier: cast.string
10497+
count: 2
10498+
path: src/Plugins.php
10499+
1051810500
-
1051910501
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
1052010502
identifier: empty.notAllowed
@@ -10533,54 +10515,18 @@ parameters:
1053310515
count: 2
1053410516
path: src/Plugins.php
1053510517

10536-
-
10537-
message: '#^Method PhpMyAdmin\\Plugins\:\:getString\(\) should return string but returns mixed\.$#'
10538-
identifier: return.type
10539-
count: 1
10540-
path: src/Plugins.php
10541-
1054210518
-
1054310519
message: '#^Parameter \#1 \$link of static method PhpMyAdmin\\Html\\MySQLDocumentation\:\:show\(\) expects string, mixed given\.$#'
1054410520
identifier: argument.type
1054510521
count: 2
1054610522
path: src/Plugins.php
1054710523

10548-
-
10549-
message: '#^Parameter \#1 \$name of static method PhpMyAdmin\\Plugins\:\:getString\(\) expects string\|null, mixed given\.$#'
10550-
identifier: argument.type
10551-
count: 2
10552-
path: src/Plugins.php
10553-
10554-
-
10555-
message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, bool\|int\<0, max\>\|string given\.$#'
10556-
identifier: argument.type
10557-
count: 1
10558-
path: src/Plugins.php
10559-
10560-
-
10561-
message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, mixed given\.$#'
10562-
identifier: argument.type
10563-
count: 2
10564-
path: src/Plugins.php
10565-
1056610524
-
1056710525
message: '#^Parameter \#2 \$anchor of static method PhpMyAdmin\\Html\\MySQLDocumentation\:\:showDocumentation\(\) expects string, mixed given\.$#'
1056810526
identifier: argument.type
1056910527
count: 1
1057010528
path: src/Plugins.php
1057110529

10572-
-
10573-
message: '#^Parameter \#2 \$replace of function str_replace expects array\<string\>\|string, mixed given\.$#'
10574-
identifier: argument.type
10575-
count: 1
10576-
path: src/Plugins.php
10577-
10578-
-
10579-
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, bool\|int\<0, max\>\|string given\.$#'
10580-
identifier: argument.type
10581-
count: 1
10582-
path: src/Plugins.php
10583-
1058410530
-
1058510531
message: '#^Parameter \#5 \$anchor of static method PhpMyAdmin\\Html\\MySQLDocumentation\:\:show\(\) expects string, mixed given\.$#'
1058610532
identifier: argument.type

psalm-baseline.xml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,8 @@
927927
<file src="src/Controllers/Database/ImportController.php">
928928
<DeprecatedMethod>
929929
<code><![CDATA[Config::getInstance()]]></code>
930+
<code><![CDATA[Config::getInstance()]]></code>
931+
<code><![CDATA[Config::getInstance()]]></code>
930932
</DeprecatedMethod>
931933
<MixedArrayAccess>
932934
<code><![CDATA[$_SESSION[Ajax::SESSION_KEY]['handler']]]></code>
@@ -1968,6 +1970,8 @@
19681970
<file src="src/Controllers/Server/ImportController.php">
19691971
<DeprecatedMethod>
19701972
<code><![CDATA[Config::getInstance()]]></code>
1973+
<code><![CDATA[Config::getInstance()]]></code>
1974+
<code><![CDATA[Config::getInstance()]]></code>
19711975
</DeprecatedMethod>
19721976
<MixedArrayAccess>
19731977
<code><![CDATA[$_SESSION[Ajax::SESSION_KEY]['handler']]]></code>
@@ -2574,6 +2578,8 @@
25742578
<file src="src/Controllers/Table/ImportController.php">
25752579
<DeprecatedMethod>
25762580
<code><![CDATA[Config::getInstance()]]></code>
2581+
<code><![CDATA[Config::getInstance()]]></code>
2582+
<code><![CDATA[Config::getInstance()]]></code>
25772583
</DeprecatedMethod>
25782584
<MixedArrayAccess>
25792585
<code><![CDATA[$_SESSION[Ajax::SESSION_KEY]['handler']]]></code>
@@ -3598,6 +3604,7 @@
35983604
<file src="src/Database/Designer.php">
35993605
<DeprecatedMethod>
36003606
<code><![CDATA[Config::getInstance()]]></code>
3607+
<code><![CDATA[Config::getInstance()]]></code>
36013608
</DeprecatedMethod>
36023609
<MixedAssignment>
36033610
<code><![CDATA[$params]]></code>
@@ -3609,9 +3616,6 @@
36093616
<code><![CDATA[$params]]></code>
36103617
<code><![CDATA[$params]]></code>
36113618
</MixedReturnStatement>
3612-
<PossiblyInvalidCast>
3613-
<code><![CDATA[$_GET['export_type']]]></code>
3614-
</PossiblyInvalidCast>
36153619
</file>
36163620
<file src="src/Database/Designer/Common.php">
36173621
<DeprecatedMethod>
@@ -4647,6 +4651,7 @@
46474651
<code><![CDATA[Config::getInstance()]]></code>
46484652
<code><![CDATA[Config::getInstance()]]></code>
46494653
<code><![CDATA[Config::getInstance()]]></code>
4654+
<code><![CDATA[Config::getInstance()]]></code>
46504655
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
46514656
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
46524657
</DeprecatedMethod>
@@ -4659,9 +4664,6 @@
46594664
<PossiblyInvalidArgument>
46604665
<code><![CDATA[$_POST['filename_template'] ?? null]]></code>
46614666
</PossiblyInvalidArgument>
4662-
<PossiblyInvalidCast>
4663-
<code><![CDATA[$_GET['what']]]></code>
4664-
</PossiblyInvalidCast>
46654667
<RiskyTruthyFalsyComparison>
46664668
<code><![CDATA[$config->settings['Export'][$str]]]></code>
46674669
<code><![CDATA[empty($config->settings['SaveDir'])]]></code>
@@ -6234,39 +6236,22 @@
62346236
<code><![CDATA[Config::getInstance()]]></code>
62356237
</DeprecatedMethod>
62366238
<MixedArgument>
6237-
<code><![CDATA[$GLOBALS[$match]]]></code>
62386239
<code><![CDATA[$doc[0]]]></code>
62396240
<code><![CDATA[$doc[1]]]></code>
62406241
<code><![CDATA[$doc[1]]]></code>
62416242
<code><![CDATA[$doc[2]]]></code>
6242-
<code><![CDATA[$val]]></code>
6243-
<code><![CDATA[$val]]></code>
62446243
</MixedArgument>
62456244
<MixedAssignment>
62466245
<code><![CDATA[$doc]]></code>
62476246
<code><![CDATA[$propertyItem]]></code>
62486247
<code><![CDATA[$val]]></code>
62496248
<code><![CDATA[$val]]></code>
62506249
</MixedAssignment>
6251-
<MixedInferredReturnType>
6252-
<code><![CDATA[string]]></code>
6253-
</MixedInferredReturnType>
62546250
<MixedMethodCall>
62556251
<code><![CDATA[new $class()]]></code>
62566252
</MixedMethodCall>
6257-
<MixedReturnStatement>
6258-
<code><![CDATA[$GLOBALS[$name] ?? $name ?? '']]></code>
6259-
<code><![CDATA[$GLOBALS[$name] ?? $name ?? '']]></code>
6260-
</MixedReturnStatement>
6261-
<PossiblyInvalidArgument>
6262-
<code><![CDATA[$_GET[$opt]]]></code>
6263-
<code><![CDATA[$_REQUEST[$opt]]]></code>
6264-
<code><![CDATA[$val]]></code>
6265-
<code><![CDATA[$val]]></code>
6266-
</PossiblyInvalidArgument>
62676253
<PossiblyInvalidCast>
62686254
<code><![CDATA[$config->settings[$section][$opt]]]></code>
6269-
<code><![CDATA[$config->settings[$section][$opt]]]></code>
62706255
</PossiblyInvalidCast>
62716256
<PossiblyNullOperand>
62726257
<code><![CDATA[$pitem->getName()]]></code>
@@ -12386,6 +12371,9 @@
1238612371
<code><![CDATA[$config->selectedServer]]></code>
1238712372
<code><![CDATA[$config->selectedServer]]></code>
1238812373
</InvalidPropertyAssignmentValue>
12374+
<PossiblyUnusedMethod>
12375+
<code><![CDATA[providerForGetTranslatedText]]></code>
12376+
</PossiblyUnusedMethod>
1238912377
</file>
1239012378
<file src="tests/unit/Plugins/Export/ExportOdtTest.php">
1239112379
<DeprecatedMethod>

src/Controllers/Database/DesignerController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public function __invoke(ServerRequest $request): Response
5252
$html = $this->databaseDesigner->getHtmlForSchemaExport(
5353
$db,
5454
(int) $request->getParsedBodyParamAsStringOrNull('selected_page'),
55+
$request->getParam('format'),
56+
$request->getParam('export_type'),
5557
);
5658
} elseif ($dialog === 'add_table') {
5759
// Pass the db and table to the getTablesInfo so we only have the table we asked for

src/Controllers/Database/ExportController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ public function __invoke(ServerRequest $request): Response
140140
Current::$numTables,
141141
0,
142142
$exportList,
143+
$request->getParam('format'),
144+
$request->getParam('what'),
143145
);
144146

145147
$this->response->render('database/export/index', array_merge($options, [

src/Controllers/Database/ImportController.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
use function __;
2828
use function is_numeric;
29+
use function is_string;
2930

3031
final class ImportController implements InvocableController
3132
{
@@ -92,12 +93,9 @@ public function __invoke(ServerRequest $request): Response
9293
$idKey = $_SESSION[Ajax::SESSION_KEY]['handler']::getIdKey();
9394
$hiddenInputs = [$idKey => $uploadId, 'import_type' => 'database', 'db' => Current::$database];
9495

95-
$default = $request->hasQueryParam('format')
96-
? (string) $request->getQueryParam('format')
97-
: Plugins::getDefault('Import', 'format');
98-
$choice = Plugins::getChoice($importList, $default);
96+
$choice = Plugins::getChoice($importList, $this->getFormat($request->getParam('format')));
9997
$options = Plugins::getOptions('Import', $importList);
100-
$skipQueriesDefault = Plugins::getDefault('Import', 'skip_queries');
98+
$skipQueriesDefault = $this->getSkipQueries($request->getParam('skip_queries'));
10199
$isAllowInterruptChecked = Plugins::checkboxCheck('Import', 'allow_interrupt');
102100
$maxUploadSize = (int) $config->get('max_upload_size');
103101

@@ -134,4 +132,22 @@ public function __invoke(ServerRequest $request): Response
134132

135133
return $this->response->response();
136134
}
135+
136+
private function getFormat(mixed $formatParam): string
137+
{
138+
if (is_string($formatParam) && $formatParam !== '') {
139+
return $formatParam;
140+
}
141+
142+
return Config::getInstance()->settings['Import']['format'];
143+
}
144+
145+
private function getSkipQueries(mixed $skipQueriesParam): int
146+
{
147+
if (is_numeric($skipQueriesParam) && $skipQueriesParam >= 0) {
148+
return (int) $skipQueriesParam;
149+
}
150+
151+
return Config::getInstance()->settings['Import']['skip_queries'];
152+
}
137153
}

src/Controllers/Server/ExportController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function __invoke(ServerRequest $request): Response
6666
Current::$numTables,
6767
0,
6868
$exportList,
69+
$request->getParam('format'),
70+
$request->getParam('what'),
6971
);
7072

7173
$this->response->render('server/export/index', array_merge($options, [

src/Controllers/Server/ImportController.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
use function __;
2626
use function is_numeric;
27+
use function is_string;
2728

2829
final class ImportController implements InvocableController
2930
{
@@ -74,12 +75,9 @@ public function __invoke(ServerRequest $request): Response
7475
$idKey = $_SESSION[Ajax::SESSION_KEY]['handler']::getIdKey();
7576
$hiddenInputs = [$idKey => $uploadId, 'import_type' => 'server'];
7677

77-
$default = $request->hasQueryParam('format')
78-
? (string) $request->getQueryParam('format')
79-
: Plugins::getDefault('Import', 'format');
80-
$choice = Plugins::getChoice($importList, $default);
78+
$choice = Plugins::getChoice($importList, $this->getFormat($request->getParam('format')));
8179
$options = Plugins::getOptions('Import', $importList);
82-
$skipQueriesDefault = Plugins::getDefault('Import', 'skip_queries');
80+
$skipQueriesDefault = $this->getSkipQueries($request->getParam('skip_queries'));
8381
$isAllowInterruptChecked = Plugins::checkboxCheck('Import', 'allow_interrupt');
8482
$maxUploadSize = (int) $config->get('max_upload_size');
8583

@@ -116,4 +114,22 @@ public function __invoke(ServerRequest $request): Response
116114

117115
return $this->response->response();
118116
}
117+
118+
private function getFormat(mixed $formatParam): string
119+
{
120+
if (is_string($formatParam) && $formatParam !== '') {
121+
return $formatParam;
122+
}
123+
124+
return Config::getInstance()->settings['Import']['format'];
125+
}
126+
127+
private function getSkipQueries(mixed $skipQueriesParam): int
128+
{
129+
if (is_numeric($skipQueriesParam) && $skipQueriesParam >= 0) {
130+
return (int) $skipQueriesParam;
131+
}
132+
133+
return Config::getInstance()->settings['Import']['skip_queries'];
134+
}
119135
}

0 commit comments

Comments
 (0)