Merge pull request #19326 from kamil-tekiela/getParsedBodyParamAsString

Add getParsedBodyParamAsString
This commit is contained in:
Maurício Meneghini Fauth 2024-10-21 11:02:21 -03:00 committed by GitHub
commit 39898ace83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 174 deletions

View File

@ -1420,16 +1420,6 @@ parameters:
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#1 \\$colName of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#1 \\$colName of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#1 \\$database of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:deleteColumnsFromList\\(\\) expects string, mixed given\\.$#"
count: 1
@ -1440,121 +1430,11 @@ parameters:
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#1 \\$totalRows of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:main\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#10 \\$collation of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$colDefault of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$fieldSelect of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:syncUniqueColumns\\(\\) expects array\\<string\\>, array\\<int, mixed\\> given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$origColName of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$position of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:main\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$selectedDb of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:getHtmlForEditingPage\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#2 \\$table of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:getListRaw\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#3 \\$colDefault of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#3 \\$colDefaultSel of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#4 \\$colDefaultSel of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#4 \\$colExtra of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#4 \\$containingTable of method PhpMyAdmin\\\\Database\\\\CentralColumns\\:\\:syncUniqueColumns\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#5 \\$colExtra of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#5 \\$colIsNull of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#6 \\$colIsNull of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string\\|null, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#6 \\$colLength of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#7 \\$colAttribute of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#7 \\$colLength of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#8 \\$colAttribute of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#8 \\$colType of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#9 \\$colType of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:editSave\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Parameter \\#9 \\$collation of method PhpMyAdmin\\\\Controllers\\\\Database\\\\CentralColumnsController\\:\\:addNewColumn\\(\\) expects string, mixed given\\.$#"
count: 1
path: src/Controllers/Database/CentralColumnsController.php
-
message: "#^Cannot access offset string on mixed\\.$#"
count: 1

View File

@ -853,33 +853,7 @@
<code><![CDATA[$params['col_name']]]></code>
<code><![CDATA[$params['db']]]></code>
<code><![CDATA[$params['db']]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_attribute')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_attribute')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_default')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_default')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_default_sel')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_default_sel')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_extra')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_extra')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_isNull')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_isNull')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_length')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_length')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_name')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_name')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_type')]]></code>
<code><![CDATA[$request->getParsedBodyParam('col_type')]]></code>
<code><![CDATA[$request->getParsedBodyParam('collation')]]></code>
<code><![CDATA[$request->getParsedBodyParam('collation')]]></code>
<code><![CDATA[$request->getParsedBodyParam('cur_table', '')]]></code>
<code><![CDATA[$request->getParsedBodyParam('orig_col_name')]]></code>
<code><![CDATA[$request->getParsedBodyParam('pos', '')]]></code>
<code><![CDATA[$request->getParsedBodyParam('table-select')]]></code>
<code><![CDATA[$request->getParsedBodyParam('total_rows', '')]]></code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code><![CDATA[[$request->getParsedBodyParam('column-select')]]]></code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code><![CDATA[$GLOBALS['message']]]></code>
</MixedAssignment>

View File

@ -18,10 +18,8 @@ final class ColumnController implements InvocableController
public function __invoke(ServerRequest $request): Response
{
/** @var string|null $db */
$db = $request->getParsedBodyParam('db');
/** @var string|null $table */
$table = $request->getParsedBodyParam('table');
$db = $request->getParsedBodyParamAsStringOrNull('db');
$table = $request->getParsedBodyParamAsStringOrNull('table');
if (! isset($db, $table)) {
$this->response->setRequestStatus(false);

View File

@ -38,16 +38,16 @@ final class CentralColumnsController implements InvocableController
if ($request->hasBodyParam('edit_save')) {
$this->response->addHTML((string) $this->editSave(
$request->getParsedBodyParam('col_name'),
$request->getParsedBodyParam('orig_col_name'),
$request->getParsedBodyParam('col_default'),
$request->getParsedBodyParam('col_default_sel'),
$request->getParsedBodyParam('col_extra'),
$request->getParsedBodyParam('col_isNull'),
$request->getParsedBodyParam('col_length'),
$request->getParsedBodyParam('col_attribute'),
$request->getParsedBodyParam('col_type'),
$request->getParsedBodyParam('collation'),
$request->getParsedBodyParamAsString('col_name'),
$request->getParsedBodyParamAsString('orig_col_name'),
$request->getParsedBodyParamAsString('col_default'),
$request->getParsedBodyParamAsString('col_default_sel'),
$request->getParsedBodyParamAsStringOrNull('col_extra'),
$request->getParsedBodyParamAsStringOrNull('col_isNull'),
$request->getParsedBodyParamAsString('col_length'),
$request->getParsedBodyParamAsString('col_attribute'),
$request->getParsedBodyParamAsString('col_type'),
$request->getParsedBodyParamAsString('collation'),
$db,
));
@ -56,15 +56,15 @@ final class CentralColumnsController implements InvocableController
if ($request->hasBodyParam('add_new_column')) {
$tmpMsg = $this->addNewColumn(
$request->getParsedBodyParam('col_name'),
$request->getParsedBodyParam('col_default'),
$request->getParsedBodyParam('col_default_sel'),
$request->getParsedBodyParam('col_extra'),
$request->getParsedBodyParam('col_isNull'),
$request->getParsedBodyParam('col_length'),
$request->getParsedBodyParam('col_attribute'),
$request->getParsedBodyParam('col_type'),
$request->getParsedBodyParam('collation'),
$request->getParsedBodyParamAsString('col_name'),
$request->getParsedBodyParamAsString('col_default'),
$request->getParsedBodyParamAsString('col_default_sel'),
$request->getParsedBodyParamAsStringOrNull('col_extra'),
$request->getParsedBodyParamAsStringOrNull('col_isNull'),
$request->getParsedBodyParamAsString('col_length'),
$request->getParsedBodyParamAsString('col_attribute'),
$request->getParsedBodyParamAsString('col_type'),
$request->getParsedBodyParamAsString('collation'),
$db,
);
}
@ -72,7 +72,7 @@ final class CentralColumnsController implements InvocableController
if ($request->hasBodyParam('getColumnList')) {
$this->response->addJSON('message', $this->centralColumns->getListRaw(
$db->getName(),
$request->getParsedBodyParam('cur_table', ''),
$request->getParsedBodyParamAsString('cur_table', ''),
));
return $this->response->response();
@ -81,9 +81,9 @@ final class CentralColumnsController implements InvocableController
if ($request->hasBodyParam('add_column')) {
$tmpMsg = $this->centralColumns->syncUniqueColumns(
DatabaseName::from($request->getParsedBodyParam('db')),
[$request->getParsedBodyParam('column-select')],
[$request->getParsedBodyParamAsString('column-select')],
false,
$request->getParsedBodyParam('table-select'),
$request->getParsedBodyParamAsString('table-select'),
);
}
@ -130,8 +130,8 @@ final class CentralColumnsController implements InvocableController
}
$this->main(
$request->getParsedBodyParam('pos', ''),
$request->getParsedBodyParam('total_rows', ''),
$request->getParsedBodyParamAsString('pos', ''),
$request->getParsedBodyParamAsString('total_rows', ''),
$db,
);

View File

@ -8,6 +8,7 @@ use Fig\Http\Message\RequestMethodInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use Webmozart\Assert\Assert;
use function is_array;
use function is_object;
@ -307,4 +308,20 @@ class ServerRequest implements ServerRequestInterface
return $this->serverRequest->getHeaderLine('X-Requested-With') === 'XMLHttpRequest'
|| $this->has('ajax_request');
}
public function getParsedBodyParamAsString(string $param, string|null $default = null): string
{
$value = $this->getParsedBodyParam($param, $default);
Assert::string($value);
return $value;
}
public function getParsedBodyParamAsStringOrNull(string $param, string|null $default = null): string|null
{
$value = $this->getParsedBodyParam($param, $default);
Assert::nullOrString($value);
return $value;
}
}