diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 34442e983d..21c8adc0ce 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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\\, array\\ 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 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 62ecb5480e..a1814ee622 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -853,33 +853,7 @@ - getParsedBodyParam('col_attribute')]]> - getParsedBodyParam('col_attribute')]]> - getParsedBodyParam('col_default')]]> - getParsedBodyParam('col_default')]]> - getParsedBodyParam('col_default_sel')]]> - getParsedBodyParam('col_default_sel')]]> - getParsedBodyParam('col_extra')]]> - getParsedBodyParam('col_extra')]]> - getParsedBodyParam('col_isNull')]]> - getParsedBodyParam('col_isNull')]]> - getParsedBodyParam('col_length')]]> - getParsedBodyParam('col_length')]]> - getParsedBodyParam('col_name')]]> - getParsedBodyParam('col_name')]]> - getParsedBodyParam('col_type')]]> - getParsedBodyParam('col_type')]]> - getParsedBodyParam('collation')]]> - getParsedBodyParam('collation')]]> - getParsedBodyParam('cur_table', '')]]> - getParsedBodyParam('orig_col_name')]]> - getParsedBodyParam('pos', '')]]> - getParsedBodyParam('table-select')]]> - getParsedBodyParam('total_rows', '')]]> - - getParsedBodyParam('column-select')]]]> - diff --git a/src/Controllers/ColumnController.php b/src/Controllers/ColumnController.php index cf349d25ab..f2c7493047 100644 --- a/src/Controllers/ColumnController.php +++ b/src/Controllers/ColumnController.php @@ -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); diff --git a/src/Controllers/Database/CentralColumnsController.php b/src/Controllers/Database/CentralColumnsController.php index 2e9bc76afc..0d6957ac91 100644 --- a/src/Controllers/Database/CentralColumnsController.php +++ b/src/Controllers/Database/CentralColumnsController.php @@ -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, ); diff --git a/src/Http/ServerRequest.php b/src/Http/ServerRequest.php index 61ceb7e489..1baea1810d 100644 --- a/src/Http/ServerRequest.php +++ b/src/Http/ServerRequest.php @@ -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; + } }