Skip to content

Commit 47238d6

Browse files
committed
Fix ImportController failing test and other minor fixes
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 3794031 commit 47238d6

5 files changed

Lines changed: 64 additions & 69 deletions

File tree

libraries/classes/Controllers/Import/ImportController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function __invoke(ServerRequest $request): void
138138
// (eg. non import, but query box/window run)
139139
if (! empty($GLOBALS['sql_query'])) {
140140
// apply values for parameters
141-
/** @var array<string, string> $parameters */
141+
/** @var array<string, string>|null $parameters */
142142
$parameters = $request->getParsedBodyParam('parameters');
143143
if ($request->hasBodyParam('parameterized') && is_array($parameters)) {
144144
foreach ($parameters as $parameter => $replacementValue) {

libraries/classes/Database/Designer/Common.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public function getColumnsInfo(array $designerTables): array
128128
public function getScriptContr(array $designerTables): array
129129
{
130130
$this->dbi->selectDb($GLOBALS['db']);
131-
$con = [];
132-
$con['C_NAME'] = [];
131+
/** @var array{C_NAME: string[], DTN: string[], DCN: string[], STN: string[], SCN: string[]} $con */
132+
$con = ['C_NAME' => [], 'DTN' => [], 'DCN' => [], 'STN' => [], 'SCN' => []];
133133
$i = 0;
134134
$alltab_rs = $this->dbi->query('SHOW TABLES FROM ' . Util::backquote($GLOBALS['db']));
135135
while ($val = $alltab_rs->fetchRow()) {

phpstan-baseline.neon

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,26 @@ parameters:
14251425
count: 1
14261426
path: libraries/classes/Controllers/HomeController.php
14271427

1428+
-
1429+
message: "#^Cannot cast mixed to int\\.$#"
1430+
count: 2
1431+
path: libraries/classes/Controllers/Import/ImportController.php
1432+
1433+
-
1434+
message: "#^Parameter \\#4 \\$sqlQueryForBookmark of method PhpMyAdmin\\\\Sql\\:\\:storeTheQueryAsBookmark\\(\\) expects string, mixed given\\.$#"
1435+
count: 2
1436+
path: libraries/classes/Controllers/Import/ImportController.php
1437+
1438+
-
1439+
message: "#^Parameter \\#5 \\$bookmarkLabel of method PhpMyAdmin\\\\Sql\\:\\:storeTheQueryAsBookmark\\(\\) expects string, mixed given\\.$#"
1440+
count: 2
1441+
path: libraries/classes/Controllers/Import/ImportController.php
1442+
1443+
-
1444+
message: "#^Parameter \\#1 \\$id of static method PhpMyAdmin\\\\Import\\\\Ajax\\:\\:status\\(\\) expects string, mixed given\\.$#"
1445+
count: 1
1446+
path: libraries/classes/Controllers/Import/StatusController.php
1447+
14281448
-
14291449
message: "#^Parameter \\#1 \\$database of method PhpMyAdmin\\\\Navigation\\\\Navigation\\:\\:getItemUnhideDialog\\(\\) expects string, mixed given\\.$#"
14301450
count: 1
@@ -2395,26 +2415,6 @@ parameters:
23952415
count: 1
23962416
path: libraries/classes/Database/Designer/Common.php
23972417

2398-
-
2399-
message: "#^Offset 'DCN' does not exist on array\\{C_NAME\\: array\\{\\}\\}\\|array\\{C_NAME\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, DCN\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, DTN\\: non\\-empty\\-array\\<int\\<0, max\\>, non\\-falsy\\-string\\>, SCN\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, STN\\: non\\-empty\\-array\\<int\\<0, max\\>, non\\-falsy\\-string\\>\\}\\.$#"
2400-
count: 1
2401-
path: libraries/classes/Database/Designer/Common.php
2402-
2403-
-
2404-
message: "#^Offset 'DTN' does not exist on array\\{C_NAME\\: array\\{\\}\\}\\|array\\{C_NAME\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, DCN\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, DTN\\: non\\-empty\\-array\\<int\\<0, max\\>, non\\-falsy\\-string\\>, SCN\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, STN\\: non\\-empty\\-array\\<int\\<0, max\\>, non\\-falsy\\-string\\>\\}\\.$#"
2405-
count: 1
2406-
path: libraries/classes/Database/Designer/Common.php
2407-
2408-
-
2409-
message: "#^Offset 'SCN' does not exist on array\\{C_NAME\\: array\\{\\}\\}\\|array\\{C_NAME\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, DCN\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, DTN\\: non\\-empty\\-array\\<int\\<0, max\\>, non\\-falsy\\-string\\>, SCN\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, STN\\: non\\-empty\\-array\\<int\\<0, max\\>, non\\-falsy\\-string\\>\\}\\.$#"
2410-
count: 1
2411-
path: libraries/classes/Database/Designer/Common.php
2412-
2413-
-
2414-
message: "#^Offset 'STN' does not exist on array\\{C_NAME\\: array\\{\\}\\}\\|array\\{C_NAME\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, DCN\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, DTN\\: non\\-empty\\-array\\<int\\<0, max\\>, non\\-falsy\\-string\\>, SCN\\: non\\-empty\\-array\\<int\\<0, max\\>, string\\>, STN\\: non\\-empty\\-array\\<int\\<0, max\\>, non\\-falsy\\-string\\>\\}\\.$#"
2415-
count: 2
2416-
path: libraries/classes/Database/Designer/Common.php
2417-
24182418
-
24192419
message: "#^Method PhpMyAdmin\\\\Database\\\\Events\\:\\:checkResult\\(\\) has parameter \\$errors with no value type specified in iterable type array\\.$#"
24202420
count: 1
@@ -5980,6 +5980,11 @@ parameters:
59805980
count: 1
59815981
path: libraries/classes/Plugins/Export/ExportSql.php
59825982

5983+
-
5984+
message: "#^Casting to string something that's already string\\.$#"
5985+
count: 2
5986+
path: libraries/classes/Plugins/Export/ExportSql.php
5987+
59835988
-
59845989
message: "#^Method PhpMyAdmin\\\\Plugins\\\\Export\\\\ExportSql\\:\\:exportData\\(\\) has parameter \\$aliases with no value type specified in iterable type array\\.$#"
59855990
count: 1
@@ -9045,11 +9050,6 @@ parameters:
90459050
count: 1
90469051
path: libraries/classes/VersionInformation.php
90479052

9048-
-
9049-
message: "#^Call to function is_array\\(\\) with array will always evaluate to true\\.$#"
9050-
count: 1
9051-
path: libraries/classes/ZipExtension.php
9052-
90539053
-
90549054
message: "#^Method PhpMyAdmin\\\\ZipExtension\\:\\:createFile\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
90559055
count: 1

psalm-baseline.xml

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,21 +2148,27 @@
21482148
<DocblockTypeContradiction occurrences="1">
21492149
<code>$import_plugin == null</code>
21502150
</DocblockTypeContradiction>
2151-
<InvalidArgument occurrences="1">
2152-
<code>$GLOBALS['urlParams']</code>
2153-
</InvalidArgument>
21542151
<InvalidArrayOffset occurrences="1">
21552152
<code>$GLOBALS['cfg']['AllowUserDropDatabase']</code>
21562153
</InvalidArrayOffset>
2157-
<MixedArgument occurrences="7">
2154+
<MixedArgument occurrences="13">
21582155
<code>$GLOBALS['cfg']['AllowUserDropDatabase']</code>
21592156
<code>$GLOBALS['cfg']['MemoryLimit']</code>
2157+
<code>$GLOBALS['format']</code>
21602158
<code>$GLOBALS['import_notice']</code>
2159+
<code>$GLOBALS['local_import_file']</code>
21612160
<code>$_SESSION['Import_message']['go_back_url']</code>
21622161
<code>$die['error']</code>
21632162
<code>$die['sql']</code>
21642163
<code>$importHandle ?? null</code>
2164+
<code>$request-&gt;getParsedBodyParam('bkm_label')</code>
2165+
<code>$request-&gt;getParsedBodyParam('bkm_label')</code>
2166+
<code>$request-&gt;getParsedBodyParam('sql_query')</code>
2167+
<code>$request-&gt;getParsedBodyParam('sql_query')</code>
21652168
</MixedArgument>
2169+
<MixedArgumentTypeCoercion occurrences="1">
2170+
<code>$GLOBALS['urlParams']</code>
2171+
</MixedArgumentTypeCoercion>
21662172
<MixedArrayAccess occurrences="3">
21672173
<code>$_SESSION['Import_message']['go_back_url']</code>
21682174
<code>$die['error']</code>
@@ -2180,56 +2186,54 @@
21802186
<code>$_SESSION['Import_message']['message']</code>
21812187
<code>$_SESSION['Import_message']['message']</code>
21822188
</MixedArrayAssignment>
2183-
<MixedAssignment occurrences="22">
2189+
<MixedAssignment occurrences="35">
2190+
<code>$GLOBALS['MAX_FILE_SIZE']</code>
21842191
<code>$GLOBALS['active_page']</code>
21852192
<code>$GLOBALS['ajax_reload']</code>
21862193
<code>$GLOBALS['charset_conversion']</code>
2194+
<code>$GLOBALS['charset_of_file']</code>
21872195
<code>$GLOBALS['errorUrl']</code>
21882196
<code>$GLOBALS['executed_queries']</code>
2197+
<code>$GLOBALS['format']</code>
21892198
<code>$GLOBALS['go_sql']</code>
21902199
<code>$GLOBALS['import_file']</code>
21912200
<code>$GLOBALS['import_notice']</code>
2201+
<code>$GLOBALS['import_type']</code>
2202+
<code>$GLOBALS['is_js_confirmed']</code>
2203+
<code>$GLOBALS['local_import_file']</code>
21922204
<code>$GLOBALS['max_sql_len']</code>
21932205
<code>$GLOBALS['maximum_time']</code>
2206+
<code>$GLOBALS['message_to_show']</code>
21942207
<code>$GLOBALS['msg']</code>
21952208
<code>$GLOBALS['my_die']</code>
2209+
<code>$GLOBALS['noplugin']</code>
21962210
<code>$GLOBALS['read_multiply']</code>
21972211
<code>$GLOBALS['reload']</code>
21982212
<code>$GLOBALS['reset_charset']</code>
21992213
<code>$GLOBALS['result']</code>
22002214
<code>$GLOBALS['run_query']</code>
2215+
<code>$GLOBALS['show_as_php']</code>
2216+
<code>$GLOBALS['skip_queries']</code>
22012217
<code>$GLOBALS['sql_file']</code>
22022218
<code>$GLOBALS['sql_query_disabled']</code>
22032219
<code>$GLOBALS['timeout_passed']</code>
22042220
<code>$GLOBALS['timestamp']</code>
2221+
<code>$GLOBALS['urlParams']['local_import_file']</code>
2222+
<code>$bookmark_variables</code>
2223+
<code>$console_message_id</code>
22052224
<code>$die</code>
22062225
</MixedAssignment>
22072226
<MixedMethodCall occurrences="1">
22082227
<code>close</code>
22092228
</MixedMethodCall>
2210-
<PossiblyInvalidArgument occurrences="8">
2229+
<MixedOperand occurrences="3">
2230+
<code>$GLOBALS['charset_of_file']</code>
22112231
<code>$GLOBALS['format']</code>
22122232
<code>$GLOBALS['local_import_file']</code>
2213-
<code>$_POST['bkm_label']</code>
2214-
<code>$_POST['bkm_label']</code>
2215-
<code>$_POST['bookmark_variable']</code>
2216-
<code>$_POST['sql_query']</code>
2217-
<code>$_POST['sql_query']</code>
2233+
</MixedOperand>
2234+
<PossiblyInvalidArgument occurrences="1">
22182235
<code>$skip &lt; $GLOBALS['read_limit'] ? $skip : $GLOBALS['read_limit']</code>
22192236
</PossiblyInvalidArgument>
2220-
<PossiblyInvalidCast occurrences="6">
2221-
<code>$GLOBALS['format']</code>
2222-
<code>$GLOBALS['local_import_file']</code>
2223-
<code>$_POST['bkm_label']</code>
2224-
<code>$_POST['bkm_label']</code>
2225-
<code>$_POST['sql_query']</code>
2226-
<code>$_POST['sql_query']</code>
2227-
</PossiblyInvalidCast>
2228-
<PossiblyInvalidOperand occurrences="3">
2229-
<code>$GLOBALS['charset_of_file']</code>
2230-
<code>$GLOBALS['format']</code>
2231-
<code>$GLOBALS['local_import_file']</code>
2232-
</PossiblyInvalidOperand>
22332237
<PossiblyNullArgument occurrences="1">
22342238
<code>$GLOBALS['collation_connection']</code>
22352239
</PossiblyNullArgument>
@@ -2241,18 +2245,16 @@
22412245
<code>$GLOBALS['offset'] == 0</code>
22422246
<code>$GLOBALS['result'] === false</code>
22432247
</RedundantCondition>
2244-
<RiskyCast occurrences="1">
2245-
<code>$_POST['id_bookmark']</code>
2246-
</RiskyCast>
22472248
<TypeDoesNotContainType occurrences="3">
22482249
<code>$GLOBALS['finished']</code>
22492250
<code>$GLOBALS['result']</code>
22502251
<code>$GLOBALS['timeout_passed']</code>
22512252
</TypeDoesNotContainType>
22522253
</file>
22532254
<file src="libraries/classes/Controllers/Import/StatusController.php">
2254-
<MixedArgument occurrences="1">
2255+
<MixedArgument occurrences="2">
22552256
<code>$_SESSION['Import_message']['message'] ?? ''</code>
2257+
<code>$request-&gt;getQueryParam('id')</code>
22562258
</MixedArgument>
22572259
<MixedArrayAssignment occurrences="1">
22582260
<code>$_SESSION['Import_message']['message']</code>
@@ -2262,12 +2264,6 @@
22622264
<code>$GLOBALS['timestamp']</code>
22632265
<code>$GLOBALS['upload_id']</code>
22642266
</MixedAssignment>
2265-
<PossiblyInvalidArgument occurrences="1">
2266-
<code>$_GET['id']</code>
2267-
</PossiblyInvalidArgument>
2268-
<PossiblyInvalidCast occurrences="1">
2269-
<code>$_GET['id']</code>
2270-
</PossiblyInvalidCast>
22712267
</file>
22722268
<file src="libraries/classes/Controllers/LintController.php">
22732269
<MixedAssignment occurrences="1">
@@ -4861,12 +4857,6 @@
48614857
<code>$index_array1</code>
48624858
<code>$index_array2</code>
48634859
</PossiblyNullArrayOffset>
4864-
<PossiblyUndefinedArrayOffset occurrences="4">
4865-
<code>$con['DCN']</code>
4866-
<code>$con['DTN']</code>
4867-
<code>$con['SCN']</code>
4868-
<code>$con['STN']</code>
4869-
</PossiblyUndefinedArrayOffset>
48704860
</file>
48714861
<file src="libraries/classes/Database/Events.php">
48724862
<DeprecatedMethod occurrences="9">

test/classes/Controllers/Import/ImportControllerTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ public function testIndexParametrized(): void
5353
$request->method('getParsedBodyParam')->willReturnMap([
5454
['db', null, $GLOBALS['db']],
5555
['table', null, $GLOBALS['table']],
56-
['parameterized', null, 'on'],
5756
['parameters', null, [':nomEta' => 'Saint-Louis - Châteaulin', ':1' => '4']],
5857
['sql_query', null, $GLOBALS['sql_query']],
5958
]);
59+
$request->method('hasBodyParam')->willReturnMap([
60+
['parameterized', true],
61+
['rollback_query', false],
62+
['allow_interrupt', false],
63+
['skip', false],
64+
]);
6065

6166
$this->dummyDbi->addResult(
6267
'SELECT A.* FROM table1 A WHERE A.nomEtablissement = \'Saint-Louis - Châteaulin\''

0 commit comments

Comments
 (0)