From 3ff024fe9d520a26448aa2f726128243eb4e336c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 10 Oct 2026 18:11:39 -0300 Subject: [PATCH] Get export_item param from ServerRequest object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- phpstan-baseline.neon | 26 ++---------- psalm-baseline.xml | 12 ------ src/Controllers/Database/EventsController.php | 18 +++++--- .../Database/RoutinesController.php | 41 +++++++++---------- 4 files changed, 36 insertions(+), 61 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 12b8adec6e..e27f2254d5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1374,13 +1374,13 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' identifier: empty.notAllowed - count: 16 + count: 14 path: src/Controllers/Database/EventsController.php - message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#' identifier: argument.type - count: 2 + count: 1 path: src/Controllers/Database/EventsController.php - @@ -1401,12 +1401,6 @@ parameters: count: 1 path: src/Controllers/Database/EventsController.php - - - message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Events\:\:getDefinition\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Database/EventsController.php - - message: '#^Cannot access offset ''handler'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -1434,7 +1428,7 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' identifier: empty.notAllowed - count: 23 + count: 21 path: src/Controllers/Database/RoutinesController.php - @@ -1446,7 +1440,7 @@ parameters: - message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#' identifier: argument.type - count: 4 + count: 3 path: src/Controllers/Database/RoutinesController.php - @@ -1473,18 +1467,6 @@ parameters: count: 3 path: src/Controllers/Database/RoutinesController.php - - - message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getFunctionDefinition\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Database/RoutinesController.php - - - - message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getProcedureDefinition\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Controllers/Database/RoutinesController.php - - message: '#^Parameter \#4 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getDetails\(\) expects string, mixed given\.$#' identifier: argument.type diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a68aaf98a9..2b37c8eb13 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -714,21 +714,16 @@ - - - - - @@ -790,9 +785,6 @@ - - - @@ -807,8 +799,6 @@ - - @@ -826,8 +816,6 @@ - - diff --git a/src/Controllers/Database/EventsController.php b/src/Controllers/Database/EventsController.php index adce8dcbd1..f1608693d1 100644 --- a/src/Controllers/Database/EventsController.php +++ b/src/Controllers/Database/EventsController.php @@ -20,6 +20,7 @@ use PhpMyAdmin\Util; use function __; use function htmlspecialchars; +use function is_string; use function mb_strtoupper; use function sprintf; use function trim; @@ -203,18 +204,18 @@ final readonly class EventsController implements InvocableController $this->response->addHTML($message); } - if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) { - $itemName = $_GET['item_name']; - $exportData = Events::getDefinition($this->dbi, Current::$database, $itemName); + $eventName = $this->getEventName($request->getQueryParam('item_name')); + if ($request->hasQueryParam('export_item') && $eventName !== '') { + $exportData = Events::getDefinition($this->dbi, Current::$database, $eventName); if ($exportData === null || $exportData === '') { $exportData = false; } - $itemName = Util::backquote($itemName); + $eventName = Util::backquote($eventName); if ($exportData !== false) { $exportData = trim($exportData); - $title = sprintf(__('Export of event %s'), $itemName); + $title = sprintf(__('Export of event %s'), $eventName); if ($request->isAjax()) { $this->response->addJSON('message', $exportData); @@ -235,7 +236,7 @@ final readonly class EventsController implements InvocableController } else { $message = sprintf( __('Error in processing request: No event with name %1$s found in database %2$s.'), - htmlspecialchars($itemName), + htmlspecialchars($eventName), htmlspecialchars(Util::backquote(Current::$database)), ); $message = Message::error($message); @@ -263,4 +264,9 @@ final readonly class EventsController implements InvocableController return $this->response->response(); } + + private function getEventName(mixed $param): string + { + return is_string($param) ? $param : ''; + } } diff --git a/src/Controllers/Database/RoutinesController.php b/src/Controllers/Database/RoutinesController.php index a578e0ea4d..70d8200fa0 100644 --- a/src/Controllers/Database/RoutinesController.php +++ b/src/Controllers/Database/RoutinesController.php @@ -29,6 +29,7 @@ use PhpMyAdmin\Util; use function __; use function htmlspecialchars; use function in_array; +use function is_string; use function max; use function mb_strtoupper; use function sprintf; @@ -362,25 +363,13 @@ final readonly class RoutinesController implements InvocableController } } - /** @var mixed $routineType */ - $routineType = $request->getQueryParam('item_type'); - if ( - ! empty($_GET['export_item']) - && ! empty($_GET['item_name']) - && in_array($routineType, ['FUNCTION', 'PROCEDURE'], true) - ) { - if ($routineType === 'FUNCTION') { - $routineDefinition = Routines::getFunctionDefinition( - $this->dbi, - Current::$database, - $_GET['item_name'], - ); + $routineType = $this->getRoutineType($request->getQueryParam('item_type')); + $routineName = $this->getRoutineName($request->getQueryParam('item_name')); + if ($request->hasQueryParam('export_item') && $routineName !== '' && $routineType !== null) { + if ($routineType === RoutineType::Function) { + $routineDefinition = Routines::getFunctionDefinition($this->dbi, Current::$database, $routineName); } else { - $routineDefinition = Routines::getProcedureDefinition( - $this->dbi, - Current::$database, - $_GET['item_name'], - ); + $routineDefinition = Routines::getProcedureDefinition($this->dbi, Current::$database, $routineName); } $exportData = false; @@ -389,10 +378,10 @@ final readonly class RoutinesController implements InvocableController $exportData = "DELIMITER $$\n" . $routineDefinition . "$$\nDELIMITER ;\n"; } - $itemName = Util::backquote($_GET['item_name']); + $routineName = Util::backquote($routineName); if ($exportData !== false) { $exportData = trim($exportData); - $title = sprintf(__('Export of routine %s'), $itemName); + $title = sprintf(__('Export of routine %s'), $routineName); if ($request->isAjax()) { $this->response->addJSON('message', $exportData); @@ -414,7 +403,7 @@ final readonly class RoutinesController implements InvocableController 'Error in processing request: No routine with name %1$s found in database %2$s.' . ' You might be lacking the necessary privileges to view/export this routine.', ), - htmlspecialchars($itemName), + htmlspecialchars($routineName), htmlspecialchars(Util::backquote(Current::$database)), ); $message = Message::error($message); @@ -490,4 +479,14 @@ final readonly class RoutinesController implements InvocableController return $this->response->response(); } + + private function getRoutineType(mixed $param): RoutineType|null + { + return is_string($param) ? RoutineType::tryFrom($param) : null; + } + + private function getRoutineName(mixed $param): string + { + return is_string($param) ? $param : ''; + } }