Use RoutineType in getQueryFromRequest

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2025-04-30 22:32:57 +01:00
parent 3c88ec1457
commit 51f8dc5926
3 changed files with 18 additions and 17 deletions

View File

@ -5337,7 +5337,7 @@ parameters:
-
message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, mixed given\.$#'
identifier: argument.type
count: 2
count: 1
path: src/Database/Routines.php
-
@ -5358,6 +5358,12 @@ parameters:
count: 4
path: src/Database/Routines.php
-
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Database\\RoutineType\:\:tryFrom\(\) expects int\|string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/Database/Routines.php
-
message: '#^Parameter \#2 \$array of function implode expects array\|null, list\<string\|null\>\|string given\.$#'
identifier: argument.type
@ -5413,7 +5419,7 @@ parameters:
path: src/Database/Routines.php
-
message: '#^Parameter \#7 \$itemType of method PhpMyAdmin\\Database\\Routines\:\:processParamsAndBuild\(\) expects string, mixed given\.$#'
message: '#^Parameter \#7 \$itemType of method PhpMyAdmin\\Database\\Routines\:\:processParamsAndBuild\(\) expects PhpMyAdmin\\Database\\RoutineType, PhpMyAdmin\\Database\\RoutineType\|null given\.$#'
identifier: argument.type
count: 1
path: src/Database/Routines.php

View File

@ -3579,14 +3579,13 @@
<code><![CDATA[$_POST['item_returnopts_num']]]></code>
<code><![CDATA[$_POST['item_returnopts_text']]]></code>
<code><![CDATA[$_POST['item_type']]]></code>
<code><![CDATA[$_POST['item_type'] ?? '']]></code>
<code><![CDATA[$itemDefiner]]></code>
<code><![CDATA[$itemName]]></code>
<code><![CDATA[$itemReturnType]]></code>
<code><![CDATA[$itemReturnType]]></code>
<code><![CDATA[$itemReturnType]]></code>
<code><![CDATA[$itemReturnType]]></code>
<code><![CDATA[$itemType]]></code>
<code><![CDATA[$itemType]]></code>
</PossiblyInvalidArgument>
<PossiblyInvalidCast>
<code><![CDATA[$_POST['item_comment']]]></code>
@ -3603,7 +3602,6 @@
<code><![CDATA[$itemReturnType]]></code>
<code><![CDATA[$itemReturnType]]></code>
<code><![CDATA[$itemReturnType]]></code>
<code><![CDATA[$itemType]]></code>
</PossiblyInvalidCast>
<PossiblyInvalidIterator>
<code><![CDATA[$retval['item_param_dir']]]></code>
@ -3615,6 +3613,7 @@
</PossiblyInvalidOperand>
<PossiblyNullArgument>
<code><![CDATA[$createRoutine]]></code>
<code><![CDATA[$itemType]]></code>
<code><![CDATA[$param->type->parameters]]></code>
<code><![CDATA[$routine['SPECIFIC_NAME']]]></code>
<code><![CDATA[$routine['SPECIFIC_NAME']]]></code>

View File

@ -627,7 +627,6 @@ class Routines
* @param mixed[] $itemParamLength A length or not for the parameter
* @param mixed[] $itemParamOpsText An optional charset for the parameter
* @param mixed[] $itemParamOpsNum An optional parameter for a $itemParamType NUMBER
* @param string $itemType The item type (PROCEDURE/FUNCTION)
* @param bool $warnedAboutLength A boolean that will be switched if a the length warning is given
*/
private function processParamsAndBuild(
@ -637,7 +636,7 @@ class Routines
array $itemParamLength,
array $itemParamOpsText,
array $itemParamOpsNum,
string $itemType,
RoutineType $itemType,
bool &$warnedAboutLength,
): string {
$params = '';
@ -650,14 +649,14 @@ class Routines
}
if (
$itemType === 'PROCEDURE'
$itemType === RoutineType::Procedure
&& ! empty($itemParamDir[$i])
&& in_array($itemParamDir[$i], $this->directions, true)
) {
$params .= $itemParamDir[$i] . ' '
. Util::backquote($itemParamName[$i])
. ' ' . $itemParamType[$i];
} elseif ($itemType === 'FUNCTION') {
} elseif ($itemType === RoutineType::Function) {
$params .= Util::backquote($itemParamName[$i])
. ' ' . $itemParamType[$i];
} elseif (! $warnedAboutDir) {
@ -777,7 +776,7 @@ class Routines
*/
public function getQueryFromRequest(): string
{
$itemType = $_POST['item_type'] ?? '';
$itemType = RoutineType::tryFrom($_POST['item_type'] ?? '');
$itemDefiner = $_POST['item_definer'] ?? '';
$itemName = $_POST['item_name'] ?? '';
@ -804,13 +803,10 @@ class Routines
}
}
if ($itemType === 'FUNCTION' || $itemType === 'PROCEDURE') {
$query .= $itemType . ' ';
if ($itemType !== null) {
$query .= $itemType->value . ' ';
} else {
$this->errors[] = sprintf(
__('Invalid routine type: "%s"'),
htmlspecialchars($itemType),
);
$this->errors[] = __('Invalid routine type!');
}
if (! empty($itemName)) {
@ -850,7 +846,7 @@ class Routines
}
$query .= '(' . $params . ') ';
if ($itemType === 'FUNCTION') {
if ($itemType === RoutineType::Function) {
$query = $this->processFunctionSpecificParameters($query, $warnedAboutLength);
}