Skip to content

Commit

Permalink
Merge pull request phpmyadmin#19440 from MauricioFauth/ResponseRender…
Browse files Browse the repository at this point in the history
…er-checkParameters-removal

Remove the ResponseRenderer::checkParameters() method
  • Loading branch information
MauricioFauth authored Dec 10, 2024
2 parents c29067d + b68a82e commit b759e81
Show file tree
Hide file tree
Showing 42 changed files with 407 additions and 206 deletions.
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2823,12 +2823,6 @@ parameters:
count: 1
path: src/Controllers/Export/ExportController.php

-
message: '#^Cannot cast mixed to string\.$#'
identifier: cast.string
count: 1
path: src/Controllers/Export/ExportController.php

-
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
identifier: empty.notAllowed
Expand Down
227 changes: 221 additions & 6 deletions psalm-baseline.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Controllers/Database/DataDictionaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
if (! $this->response->checkParameters(['db'], true)) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$relationParameters = $this->relation->getRelationParameters();
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/DesignerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$GLOBALS['errorUrl'] = Util::getScriptNameForOption(
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/EventsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function __invoke(ServerRequest $request): Response
$this->response->addScriptFiles(['database/events.js', 'sql.js']);

if (! $request->isAjax()) {
if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$GLOBALS['errorUrl'] = Util::getScriptNameForOption(
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function __invoke(ServerRequest $request): Response

$this->response->addScriptFiles(['export.js']);

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$GLOBALS['errorUrl'] = Util::getScriptNameForOption(
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function __invoke(ServerRequest $request): Response

$this->response->addScriptFiles(['import.js']);

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$config = Config::getInstance();
Expand Down
12 changes: 4 additions & 8 deletions src/Controllers/Database/RoutinesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public function __invoke(ServerRequest $request): Response

$config = Config::getInstance();
if (! $request->isAjax()) {
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

/**
* Displays the header and tabs
*/
if (Current::$table !== '' && in_array(Current::$table, $this->dbi->getTables(Current::$database), true)) {
if (! $this->response->checkParameters(['db', 'table'])) {
return $this->response->response();
}

UrlParams::$params = ['db' => Current::$database, 'table' => Current::$table];
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($config->settings['DefaultTabTable'], 'table');
$GLOBALS['errorUrl'] .= Url::getCommon(UrlParams::$params, '&');
Expand All @@ -92,10 +92,6 @@ public function __invoke(ServerRequest $request): Response
} else {
Current::$table = '';

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
}

$GLOBALS['errorUrl'] = Util::getScriptNameForOption(
$config->settings['DefaultTabDatabase'],
'database',
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function __invoke(ServerRequest $request): Response

$this->response->addScriptFiles(['database/search.js', 'sql.js', 'makegrid.js']);

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$config = Config::getInstance();
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/SqlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function __invoke(ServerRequest $request): Response
$this->response->addHTML($this->pageSettings->getErrorHTML());
$this->response->addHTML($this->pageSettings->getHTML());

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$GLOBALS['errorUrl'] = Util::getScriptNameForOption(
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/Structure/RealRowCountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function __invoke(ServerRequest $request): Response
'table' => $_REQUEST['table'] ?? null,
];

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$GLOBALS['errorUrl'] = Util::getScriptNameForOption(
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/StructureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public function __invoke(ServerRequest $request): Response

$parameters = ['sort' => $_REQUEST['sort'] ?? null, 'sort_order' => $_REQUEST['sort_order'] ?? null];

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$config = Config::getInstance();
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Database/TrackingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function __invoke(ServerRequest $request): Response

$this->response->addScriptFiles(['vendor/jquery/jquery.tablesorter.js', 'database/tracking.js']);

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$config = Config::getInstance();
Expand Down
11 changes: 8 additions & 3 deletions src/Controllers/Export/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use function in_array;
use function ini_set;
use function is_array;
use function is_string;
use function register_shutdown_function;
use function time;

Expand Down Expand Up @@ -93,13 +94,17 @@ public function __invoke(ServerRequest $request): Response
// sanitize this parameter which will be used below in a file inclusion
$GLOBALS['what'] = Core::securePath($whatParam);

if (! $this->response->checkParameters(['what', 'export_type'])) {
return $this->response->response();
if ($GLOBALS['what'] === '') {
return $this->response->missingParameterError('what');
}

if (! is_string($GLOBALS['export_type']) || $GLOBALS['export_type'] === '') {

Check warning on line 101 in src/Controllers/Export/ExportController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "LogicalOr": --- Original +++ New @@ @@ if ($GLOBALS['what'] === '') { return $this->response->missingParameterError('what'); } - if (!is_string($GLOBALS['export_type']) || $GLOBALS['export_type'] === '') { + if (!is_string($GLOBALS['export_type']) && $GLOBALS['export_type'] === '') { return $this->response->missingParameterError('export_type'); } // export class instance, not array of properties, as before
return $this->response->missingParameterError('export_type');
}

// export class instance, not array of properties, as before
$exportPlugin = Plugins::getPlugin('export', $GLOBALS['what'], [
'export_type' => (string) $GLOBALS['export_type'],
'export_type' => $GLOBALS['export_type'],
'single_table' => isset($GLOBALS['single_table']),
]);

Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Operations/Database/CollationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$GLOBALS['errorUrl'] = Util::getScriptNameForOption(
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Operations/DatabaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ public function __invoke(ServerRequest $request): Response
$this->relation->setDbComment(Current::$database, $request->getParsedBodyParamAsString('comment'));
}

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$config = Config::getInstance();
Expand Down
8 changes: 6 additions & 2 deletions src/Controllers/Operations/TableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ public function __invoke(ServerRequest $request): Response

$this->response->addScriptFiles(['table/operations.js']);

if (! $this->response->checkParameters(['db', 'table'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

if (Current::$table === '') {
return $this->response->missingParameterError('table');
}

$isSystemSchema = Utilities::isSystemSchema(Current::$database);
Expand Down
8 changes: 6 additions & 2 deletions src/Controllers/Operations/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ public function __invoke(ServerRequest $request): Response
$GLOBALS['errorUrl'] ??= null;
$this->response->addScriptFiles(['table/operations.js']);

if (! $this->response->checkParameters(['db', 'table'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

if (Current::$table === '') {
return $this->response->missingParameterError('table');
}

UrlParams::$params = ['db' => Current::$database, 'table' => Current::$table];
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/Sql/SqlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public function __invoke(ServerRequest $request): Response

// set $goto to what will be displayed if query returns 0 rows
UrlParams::$goto = '';
} elseif (! $this->response->checkParameters(['sql_query'], true)) {
return $this->response->response();
} elseif (Current::$sqlQuery === '') {
return $this->response->missingParameterError('sql_query');
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/Controllers/Table/AddFieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ public function __invoke(ServerRequest $request): Response

$this->response->addScriptFiles(['table/structure.js']);

if (! $this->response->checkParameters(['db', 'table'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

if (Current::$table === '') {
return $this->response->missingParameterError('table');
}

$userPrivileges = $this->userPrivilegesFactory->getPrivileges();
Expand Down Expand Up @@ -186,8 +190,8 @@ public function __invoke(ServerRequest $request): Response

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

if (! $this->response->checkParameters(['server', 'db', 'table'])) {
return $this->response->response();
if (Current::$server === 0) {

Check warning on line 193 in src/Controllers/Table/AddFieldController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ return $this->response->response(); } $this->response->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js']); - if (Current::$server === 0) { + if (Current::$server === -1) { return $this->response->missingParameterError('server'); } $templateData = $this->columnsDefinition->displayForm($userPrivileges, '/table/add-field', $numFields);
return $this->response->missingParameterError('server');
}

$templateData = $this->columnsDefinition->displayForm($userPrivileges, '/table/add-field', $numFields);
Expand Down
15 changes: 2 additions & 13 deletions src/Controllers/Table/ChartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ public function __invoke(ServerRequest $request): Response
$GLOBALS['errorUrl'] ??= null;

if (isset($_REQUEST['pos'], $_REQUEST['session_max_rows']) && $request->isAjax()) {
if (
Current::$table !== '' && Current::$database !== ''
&& ! $this->response->checkParameters(['db', 'table'])
) {
return $this->response->response();
}

$this->ajax($request);

return $this->response->response();
Expand Down Expand Up @@ -82,8 +75,8 @@ public function __invoke(ServerRequest $request): Response
* Runs common work
*/
if (Current::$table !== '') {
if (! $this->response->checkParameters(['db', 'table'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$urlParams = ['db' => Current::$database, 'table' => Current::$table];
Expand Down Expand Up @@ -125,10 +118,6 @@ public function __invoke(ServerRequest $request): Response
$urlParams['goto'] = Util::getScriptNameForOption($config->settings['DefaultTabDatabase'], 'database');
$urlParams['back'] = Url::getFromRoute('/sql');

if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
}

$GLOBALS['errorUrl'] = Util::getScriptNameForOption($config->settings['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => Current::$database], '&');

Expand Down
18 changes: 4 additions & 14 deletions src/Controllers/Table/CreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,14 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
if (! $this->response->checkParameters(['db'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

$userPrivileges = $this->userPrivilegesFactory->getPrivileges();

$cfg = $this->config->settings;

/* Check if database name is empty */
if (Current::$database === '') {
Generator::mysqlDie(
__('The database name is empty!'),
'',
false,
'index.php',
);
}

/**
* Selects the database to work with
*/
Expand Down Expand Up @@ -145,8 +135,8 @@ public function __invoke(ServerRequest $request): Response

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

if (! $this->response->checkParameters(['server', 'db'])) {
return $this->response->response();
if (Current::$server === 0) {

Check warning on line 138 in src/Controllers/Table/CreateController.php

View workflow job for this annotation

GitHub Actions / Infection (8.2, ubuntu-latest)

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ // Do not display the table in the header since it hasn't been created yet $this->response->getHeader()->getMenu()->setTable(''); $this->response->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js']); - if (Current::$server === 0) { + if (Current::$server === -1) { return $this->response->missingParameterError('server'); } $templateData = $this->columnsDefinition->displayForm($userPrivileges, '/table/create', $numFields);
return $this->response->missingParameterError('server');
}

$templateData = $this->columnsDefinition->displayForm($userPrivileges, '/table/create', $numFields);
Expand Down
8 changes: 6 additions & 2 deletions src/Controllers/Table/DeleteConfirmController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

if (! $this->response->checkParameters(['db', 'table'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

if (Current::$table === '') {
return $this->response->missingParameterError('table');
}

UrlParams::$params = ['db' => Current::$database, 'table' => Current::$table];
Expand Down
8 changes: 6 additions & 2 deletions src/Controllers/Table/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ public function __invoke(ServerRequest $request): Response

$this->response->addScriptFiles(['export.js']);

if (! $this->response->checkParameters(['db', 'table'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

if (Current::$table === '') {
return $this->response->missingParameterError('table');
}

UrlParams::$params = ['db' => Current::$database, 'table' => Current::$table];
Expand Down
8 changes: 6 additions & 2 deletions src/Controllers/Table/FindReplaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ public function __construct(
public function __invoke(ServerRequest $request): Response
{
$GLOBALS['errorUrl'] ??= null;
if (! $this->response->checkParameters(['db', 'table'])) {
return $this->response->response();
if (Current::$database === '') {
return $this->response->missingParameterError('db');
}

if (Current::$table === '') {
return $this->response->missingParameterError('table');
}

UrlParams::$params = ['db' => Current::$database, 'table' => Current::$table];
Expand Down
Loading

0 comments on commit b759e81

Please sign in to comment.