Skip to content

Commit 73844a9

Browse files
Merge pull request #18688 from kamil-tekiela/Fix-ChangeController
Fix ChangeController
2 parents e3cfca6 + 08bea00 commit 73844a9

5 files changed

Lines changed: 10 additions & 37 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5255,11 +5255,6 @@ parameters:
52555255
count: 2
52565256
path: src/Controllers/Table/AddFieldController.php
52575257

5258-
-
5259-
message: "#^Parameter \\#2 \\$numFields of method PhpMyAdmin\\\\Table\\\\ColumnsDefinition\\:\\:displayForm\\(\\) expects int, mixed given\\.$#"
5260-
count: 1
5261-
path: src/Controllers/Table/AddFieldController.php
5262-
52635258
-
52645259
message: "#^Parameter \\#2 \\$sqlQuery of static method PhpMyAdmin\\\\Html\\\\Generator\\:\\:getMessage\\(\\) expects string\\|null, mixed given\\.$#"
52655260
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3234,7 +3234,6 @@
32343234
<InvalidArrayOffset>
32353235
<code><![CDATA[$GLOBALS['active_page']]]></code>
32363236
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
3237-
<code><![CDATA[$GLOBALS['num_fields']]]></code>
32383237
<code><![CDATA[$GLOBALS['regenerate']]]></code>
32393238
<code><![CDATA[$GLOBALS['result']]]></code>
32403239
</InvalidArrayOffset>
@@ -3248,7 +3247,6 @@
32483247
<MixedAssignment>
32493248
<code><![CDATA[$GLOBALS['active_page']]]></code>
32503249
<code><![CDATA[$GLOBALS['errorUrl']]]></code>
3251-
<code><![CDATA[$GLOBALS['num_fields']]]></code>
32523250
<code><![CDATA[$GLOBALS['regenerate']]]></code>
32533251
<code><![CDATA[$GLOBALS['result']]]></code>
32543252
</MixedAssignment>
@@ -3972,16 +3970,10 @@
39723970
</PossiblyUnusedMethod>
39733971
</file>
39743972
<file src="src/Controllers/Table/Structure/ChangeController.php">
3975-
<InvalidArrayOffset>
3976-
<code><![CDATA[$GLOBALS['num_fields']]]></code>
3977-
</InvalidArrayOffset>
39783973
<MixedArgumentTypeCoercion>
39793974
<code>$selected</code>
39803975
<code><![CDATA[[$request->getParam('field')]]]></code>
39813976
</MixedArgumentTypeCoercion>
3982-
<MixedAssignment>
3983-
<code><![CDATA[$GLOBALS['num_fields']]]></code>
3984-
</MixedAssignment>
39853977
</file>
39863978
<file src="src/Controllers/Table/Structure/MoveColumnsController.php">
39873979
<MixedArgument>

src/Controllers/Table/AddFieldController.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public function __invoke(ServerRequest $request): void
5151
$GLOBALS['errorUrl'] ??= null;
5252
$GLOBALS['message'] ??= null;
5353
$GLOBALS['active_page'] ??= null;
54-
$GLOBALS['num_fields'] ??= null;
5554
$GLOBALS['regenerate'] ??= null;
5655
$GLOBALS['result'] ??= null;
5756

@@ -81,15 +80,15 @@ public function __invoke(ServerRequest $request): void
8180
$_POST['field_where'] = $_POST['orig_field_where'];
8281
}
8382

84-
$GLOBALS['num_fields'] = min(
83+
$numFields = min(
8584
intval($_POST['orig_num_fields']) + intval($_POST['added_fields']),
8685
4096,
8786
);
8887
$GLOBALS['regenerate'] = true;
8988
} elseif (is_numeric($numberOfFields) && $numberOfFields > 0) {
90-
$GLOBALS['num_fields'] = min(4096, (int) $numberOfFields);
89+
$numFields = min(4096, (int) $numberOfFields);
9190
} else {
92-
$GLOBALS['num_fields'] = 1;
91+
$numFields = 1;
9392
}
9493

9594
if (isset($_POST['do_save_data'])) {
@@ -201,15 +200,11 @@ public function __invoke(ServerRequest $request): void
201200

202201
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js']);
203202

204-
if (! $this->checkParameters(['server', 'db', 'table', 'num_fields'])) {
203+
if (! $this->checkParameters(['server', 'db', 'table'])) {
205204
return;
206205
}
207206

208-
$templateData = $this->columnsDefinition->displayForm(
209-
'/table/add-field',
210-
$GLOBALS['num_fields'],
211-
$GLOBALS['regenerate'],
212-
);
207+
$templateData = $this->columnsDefinition->displayForm('/table/add-field', $numFields, $GLOBALS['regenerate']);
213208

214209
$this->render('columns_definitions/column_definitions_form', $templateData);
215210
}

src/Controllers/Table/Structure/ChangeController.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ public function __construct(
3434

3535
public function __invoke(ServerRequest $request): void
3636
{
37-
if ($request->getParam('change_column') !== null) {
38-
if (! $this->checkParameters(['server', 'db', 'table', 'num_fields'])) {
39-
return;
40-
}
37+
if (! $this->checkParameters(['server', 'db', 'table'])) {
38+
return;
39+
}
4140

41+
if ($request->getParam('change_column') !== null) {
4242
$this->displayHtmlForColumnChange([$request->getParam('field')]);
4343

4444
return;
@@ -53,10 +53,6 @@ public function __invoke(ServerRequest $request): void
5353
return;
5454
}
5555

56-
if (! $this->checkParameters(['server', 'db', 'table', 'num_fields'])) {
57-
return;
58-
}
59-
6056
$this->displayHtmlForColumnChange($selected);
6157
}
6258

@@ -67,8 +63,6 @@ public function __invoke(ServerRequest $request): void
6763
*/
6864
private function displayHtmlForColumnChange(array $selected): void
6965
{
70-
$GLOBALS['num_fields'] ??= null;
71-
7266
$fieldsMeta = $this->dbi->getColumns($GLOBALS['db'], $GLOBALS['table'], true);
7367
$fieldsMeta = array_values(array_filter(
7468
$fieldsMeta,
@@ -87,8 +81,6 @@ private function displayHtmlForColumnChange(array $selected): void
8781
'Comment' => $column->comment,
8882
], $fieldsMeta);
8983

90-
$GLOBALS['num_fields'] = count($fieldsMeta);
91-
9284
/**
9385
* Form for changing properties.
9486
*/
@@ -99,7 +91,7 @@ private function displayHtmlForColumnChange(array $selected): void
9991

10092
$templateData = $this->columnsDefinition->displayForm(
10193
'/table/structure/save',
102-
$GLOBALS['num_fields'],
94+
count($fieldsMeta),
10395
null,
10496
$selected,
10597
$fieldsMeta,

test/classes/Controllers/Table/AddFieldControllerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public function testInvoke(): void
3030
$_POST = [
3131
'db' => 'test_db',
3232
'table' => 'test_table',
33-
'num_fields' => '1',
3433
'field_where' => 'after',
3534
'after_field' => 'datetimefield',
3635
];

0 commit comments

Comments
 (0)