diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 845be632b3..5b4c9807b2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5912,12 +5912,7 @@ parameters: - message: "#^Cannot access offset 'value' on mixed\\.$#" - count: 1 - path: src/Database/Routines.php - - - - message: "#^Cannot access offset int\\<0, max\\> on array\\\\|int\\.$#" - count: 1 + count: 2 path: src/Database/Routines.php - @@ -5932,22 +5927,22 @@ parameters: - message: "#^Cannot access property \\$name on PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\|null\\.$#" - count: 1 + count: 2 path: src/Database/Routines.php - message: "#^Cannot access property \\$options on PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\|null\\.$#" - count: 1 + count: 2 path: src/Database/Routines.php - message: "#^Cannot access property \\$options on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" - count: 1 + count: 2 path: src/Database/Routines.php - message: "#^Cannot access property \\$parameters on PhpMyAdmin\\\\SqlParser\\\\Components\\\\DataType\\|null\\.$#" - count: 1 + count: 3 path: src/Database/Routines.php - @@ -5955,6 +5950,11 @@ parameters: count: 1 path: src/Database/Routines.php + - + message: "#^Cannot assign new offset to array\\, mixed\\>\\|string\\.$#" + count: 1 + path: src/Database/Routines.php + - message: "#^Cannot call method has\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#" count: 1 @@ -6045,6 +6045,11 @@ parameters: count: 1 path: src/Database/Routines.php + - + message: "#^Parameter \\#2 \\$array of function implode expects array\\|null, array\\, mixed\\>\\|string given\\.$#" + count: 1 + path: src/Database/Routines.php + - message: "#^Parameter \\#2 \\$itemParamDir of method PhpMyAdmin\\\\Database\\\\Routines\\:\\:processParamsAndBuild\\(\\) expects array\\, array given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index fb6d736973..f11d9f7811 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -4862,9 +4862,11 @@ + + @@ -4922,8 +4924,10 @@ + + @@ -4964,9 +4968,6 @@ - - - @@ -4995,18 +4996,24 @@ + type->parameters]]> return->parameters]]> + type->options->options]]> return->options->options]]> + type->name]]> + type->options]]> + type->options->options]]> + type->parameters]]> return->name]]> return->options]]> return->options->options]]> diff --git a/src/Database/Routines.php b/src/Database/Routines.php index a133c666bb..58f67ef11b 100644 --- a/src/Database/Routines.php +++ b/src/Database/Routines.php @@ -14,7 +14,6 @@ use PhpMyAdmin\Query\Generator as QueryGenerator; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statements\CreateStatement; use PhpMyAdmin\SqlParser\TokensList; -use PhpMyAdmin\SqlParser\Utils\Routine as RoutineUtils; use PhpMyAdmin\UserPrivileges; use PhpMyAdmin\Util; @@ -459,15 +458,8 @@ class Routines $body = (string) $routine['ROUTINE_DEFINITION']; } - $params = RoutineUtils::getParameters($stmt); - $retval['item_num_params'] = $params['num']; - $retval['item_param_dir'] = $params['dir']; - $retval['item_param_name'] = $params['name']; - $retval['item_param_type'] = $params['type']; - $retval['item_param_length'] = $params['length']; - $retval['item_param_length_arr'] = $params['length_arr']; - $retval['item_param_opts_num'] = $params['opts']; - $retval['item_param_opts_text'] = $params['opts']; + $retval = array_merge($retval, $this->getParameters($stmt)); + $retval['item_param_opts_text'] = $retval['item_param_opts_num']; // Get extra data if (! $all) { @@ -518,6 +510,49 @@ class Routines return $retval; } + /** + * Gets the parameters of a routine from the parse tree. + * + * @param CreateStatement $statement the statement to be processed + * + * @return array> + */ + private function getParameters(CreateStatement $statement): array + { + $retval = [ + 'item_num_params' => 0, + 'item_param_dir' => [], + 'item_param_name' => [], + 'item_param_type' => [], + 'item_param_length' => [], + 'item_param_length_arr' => [], + 'item_param_opts_num' => [], + ]; + + if ($statement->parameters !== null) { + $idx = 0; + foreach ($statement->parameters as $param) { + $retval['item_param_dir'][$idx] = $param->inOut; + $retval['item_param_name'][$idx] = $param->name; + $retval['item_param_type'][$idx] = $param->type->name; + $retval['item_param_length'][$idx] = implode(',', $param->type->parameters); + $retval['item_param_length_arr'][$idx] = $param->type->parameters; + $retval['item_param_opts_num'][$idx] = []; + foreach ($param->type->options->options as $opt) { + $retval['item_param_opts_num'][$idx][] = is_string($opt) ? + $opt : $opt['value']; + } + + $retval['item_param_opts_num'][$idx] = implode(' ', $retval['item_param_opts_num'][$idx]); + ++$idx; + } + + $retval['item_num_params'] = $idx; + } + + return $retval; + } + /** * Creates one row for the parameter table used in the routine editor. * @@ -1169,18 +1204,16 @@ class Routines $executeAction = ''; - if ($definition !== null) { + if ($definition !== null && $hasExecutePrivilege) { $parser = new Parser('DELIMITER $$' . "\n" . $definition); /** @var CreateStatement $stmt */ $stmt = $parser->statements[0]; - $params = RoutineUtils::getParameters($stmt); - - if ($hasExecutePrivilege) { - $executeAction = 'execute_routine'; - for ($i = 0; $i < $params['num']; $i++) { - if ($routine->type === 'PROCEDURE' && $params['dir'][$i] === 'OUT') { + $executeAction = 'execute_routine'; + if ($stmt->parameters !== null) { + foreach ($stmt->parameters as $param) { + if ($routine->type === 'PROCEDURE' && $param->inOut === 'OUT') { continue; }