Skip to content

Commit fd4e7bc

Browse files
Merge pull request #19698 from kamil-tekiela/Routines-enum
Introduce enum RoutineType
2 parents bbf090c + 48b6831 commit fd4e7bc

File tree

13 files changed

+148
-189
lines changed

13 files changed

+148
-189
lines changed

phpstan-baseline.neon

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,25 +2029,25 @@ parameters:
20292029
path: src/Controllers/Database/RoutinesController.php
20302030

20312031
-
2032-
message: '#^Parameter \#2 \$type of method PhpMyAdmin\\Database\\Routines\:\:getDataFromName\(\) expects string, mixed given\.$#'
2032+
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Database\\RoutineType\:\:tryFrom\(\) expects int\|string, mixed given\.$#'
20332033
identifier: argument.type
2034-
count: 3
2034+
count: 1
20352035
path: src/Controllers/Database/RoutinesController.php
20362036

20372037
-
2038-
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getFunctionDefinition\(\) expects string, mixed given\.$#'
2038+
message: '#^Parameter \#2 \$type of method PhpMyAdmin\\Database\\Routines\:\:getDataFromName\(\) expects string, mixed given\.$#'
20392039
identifier: argument.type
2040-
count: 1
2040+
count: 3
20412041
path: src/Controllers/Database/RoutinesController.php
20422042

20432043
-
2044-
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getProcedureDefinition\(\) expects string, mixed given\.$#'
2044+
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getFunctionDefinition\(\) expects string, mixed given\.$#'
20452045
identifier: argument.type
20462046
count: 1
20472047
path: src/Controllers/Database/RoutinesController.php
20482048

20492049
-
2050-
message: '#^Parameter \#3 \$which of static method PhpMyAdmin\\Database\\Routines\:\:getDetails\(\) expects string\|null, mixed given\.$#'
2050+
message: '#^Parameter \#3 \$name of static method PhpMyAdmin\\Database\\Routines\:\:getProcedureDefinition\(\) expects string, mixed given\.$#'
20512051
identifier: argument.type
20522052
count: 1
20532053
path: src/Controllers/Database/RoutinesController.php
@@ -5193,12 +5193,6 @@ parameters:
51935193
count: 2
51945194
path: src/Database/Routines.php
51955195

5196-
-
5197-
message: '#^Binary operation "\.\=" between non\-falsy\-string and mixed results in an error\.$#'
5198-
identifier: assignOp.invalid
5199-
count: 1
5200-
path: src/Database/Routines.php
5201-
52025196
-
52035197
message: '''
52045198
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
@@ -5259,7 +5253,7 @@ parameters:
52595253
-
52605254
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
52615255
identifier: empty.notAllowed
5262-
count: 21
5256+
count: 13
52635257
path: src/Database/Routines.php
52645258

52655259
-
@@ -5292,12 +5286,6 @@ parameters:
52925286
count: 1
52935287
path: src/Database/Routines.php
52945288

5295-
-
5296-
message: '#^Parameter \#1 \$haystack of function str_contains expects string, mixed given\.$#'
5297-
identifier: argument.type
5298-
count: 1
5299-
path: src/Database/Routines.php
5300-
53015289
-
53025290
message: '#^Parameter \#1 \$haystack of function stripos expects string, mixed given\.$#'
53035291
identifier: argument.type
@@ -5307,7 +5295,7 @@ parameters:
53075295
-
53085296
message: '#^Parameter \#1 \$identifier of static method PhpMyAdmin\\Util\:\:backquote\(\) expects string\|Stringable\|null, mixed given\.$#'
53095297
identifier: argument.type
5310-
count: 9
5298+
count: 8
53115299
path: src/Database/Routines.php
53125300

53135301
-
@@ -5325,7 +5313,7 @@ parameters:
53255313
-
53265314
message: '#^Parameter \#1 \$str of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:quoteString\(\) expects string, mixed given\.$#'
53275315
identifier: argument.type
5328-
count: 7
5316+
count: 6
53295317
path: src/Database/Routines.php
53305318

53315319
-
@@ -5337,7 +5325,7 @@ parameters:
53375325
-
53385326
message: '#^Parameter \#1 \$string of function htmlspecialchars expects string, mixed given\.$#'
53395327
identifier: argument.type
5340-
count: 2
5328+
count: 1
53415329
path: src/Database/Routines.php
53425330

53435331
-
@@ -5370,12 +5358,6 @@ parameters:
53705358
count: 1
53715359
path: src/Database/Routines.php
53725360

5373-
-
5374-
message: '#^Parameter \#2 \$string of function explode expects string, mixed given\.$#'
5375-
identifier: argument.type
5376-
count: 1
5377-
path: src/Database/Routines.php
5378-
53795361
-
53805362
message: '#^Parameter \#2 \$subject of function preg_match expects string, mixed given\.$#'
53815363
identifier: argument.type
@@ -5413,7 +5395,7 @@ parameters:
54135395
path: src/Database/Routines.php
54145396

54155397
-
5416-
message: '#^Parameter \#7 \$itemType of method PhpMyAdmin\\Database\\Routines\:\:processParamsAndBuild\(\) expects string, mixed given\.$#'
5398+
message: '#^Parameter \#7 \$itemType of method PhpMyAdmin\\Database\\Routines\:\:processParamsAndBuild\(\) expects PhpMyAdmin\\Database\\RoutineType, PhpMyAdmin\\Database\\RoutineType\|null given\.$#'
54175399
identifier: argument.type
54185400
count: 1
54195401
path: src/Database/Routines.php

psalm-baseline.xml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,8 @@
973973
<code><![CDATA[$_POST['item_name']]]></code>
974974
<code><![CDATA[$_POST['item_name']]]></code>
975975
<code><![CDATA[$_POST['item_type']]]></code>
976-
<code><![CDATA[$_POST['item_type']]]></code>
977976
<code><![CDATA[$_REQUEST['item_name']]]></code>
977+
<code><![CDATA[$_REQUEST['type'] ?? '']]></code>
978978
</PossiblyInvalidArgument>
979979
<PossiblyInvalidCast>
980980
<code><![CDATA[$_GET['item_name']]]></code>
@@ -3468,10 +3468,6 @@
34683468
<code><![CDATA[Config::getInstance()]]></code>
34693469
<code><![CDATA[Config::getInstance()]]></code>
34703470
</DeprecatedMethod>
3471-
<InvalidArgument>
3472-
<code><![CDATA[$itemParamDir]]></code>
3473-
<code><![CDATA[$itemParamName]]></code>
3474-
</InvalidArgument>
34753471
<InvalidArrayOffset>
34763472
<code><![CDATA[$retval['item_param_dir'][$key]]]></code>
34773473
</InvalidArrayOffset>
@@ -3500,6 +3496,8 @@
35003496
<code><![CDATA[$value]]></code>
35013497
</MixedArgument>
35023498
<MixedArgumentTypeCoercion>
3499+
<code><![CDATA[$itemParamDir]]></code>
3500+
<code><![CDATA[$itemParamName]]></code>
35033501
<code><![CDATA[$options]]></code>
35043502
<code><![CDATA[$options]]></code>
35053503
<code><![CDATA[$retval['item_param_opts_num'][$idx]]]></code>
@@ -3546,6 +3544,9 @@
35463544
</MixedArrayOffset>
35473545
<MixedAssignment>
35483546
<code><![CDATA[$i]]></code>
3547+
<code><![CDATA[$itemParamLength]]></code>
3548+
<code><![CDATA[$itemParamName]]></code>
3549+
<code><![CDATA[$itemParamType]]></code>
35493550
<code><![CDATA[$opt]]></code>
35503551
<code><![CDATA[$opt]]></code>
35513552
<code><![CDATA[$options[]]]></code>
@@ -3565,7 +3566,6 @@
35653566
</MixedReturnTypeCoercion>
35663567
<PossiblyInvalidArgument>
35673568
<code><![CDATA[$_POST['funcs'][$routine['item_param_name'][$i]]]]></code>
3568-
<code><![CDATA[$_POST['item_comment']]]></code>
35693569
<code><![CDATA[$_POST['item_isdeterministic']]]></code>
35703570
<code><![CDATA[$_POST['item_name']]]></code>
35713571
<code><![CDATA[$_POST['item_name']]]></code>
@@ -3579,17 +3579,12 @@
35793579
<code><![CDATA[$_POST['item_returnopts_num']]]></code>
35803580
<code><![CDATA[$_POST['item_returnopts_text']]]></code>
35813581
<code><![CDATA[$_POST['item_type']]]></code>
3582-
<code><![CDATA[$itemDefiner]]></code>
3583-
<code><![CDATA[$itemName]]></code>
35843582
<code><![CDATA[$itemReturnType]]></code>
35853583
<code><![CDATA[$itemReturnType]]></code>
35863584
<code><![CDATA[$itemReturnType]]></code>
35873585
<code><![CDATA[$itemReturnType]]></code>
3588-
<code><![CDATA[$itemType]]></code>
3589-
<code><![CDATA[$itemType]]></code>
35903586
</PossiblyInvalidArgument>
35913587
<PossiblyInvalidCast>
3592-
<code><![CDATA[$_POST['item_comment']]]></code>
35933588
<code><![CDATA[$_POST['item_isdeterministic']]]></code>
35943589
<code><![CDATA[$_POST['item_name']]]></code>
35953590
<code><![CDATA[$_POST['item_original_name']]]></code>
@@ -3603,18 +3598,17 @@
36033598
<code><![CDATA[$itemReturnType]]></code>
36043599
<code><![CDATA[$itemReturnType]]></code>
36053600
<code><![CDATA[$itemReturnType]]></code>
3606-
<code><![CDATA[$itemType]]></code>
36073601
</PossiblyInvalidCast>
36083602
<PossiblyInvalidIterator>
36093603
<code><![CDATA[$retval['item_param_dir']]]></code>
36103604
</PossiblyInvalidIterator>
36113605
<PossiblyInvalidOperand>
36123606
<code><![CDATA[$_POST['item_original_type']]]></code>
36133607
<code><![CDATA[$_POST['item_returnlength']]]></code>
3614-
<code><![CDATA[$itemDefinition]]></code>
36153608
</PossiblyInvalidOperand>
36163609
<PossiblyNullArgument>
36173610
<code><![CDATA[$createRoutine]]></code>
3611+
<code><![CDATA[$itemType]]></code>
36183612
<code><![CDATA[$param->type->parameters]]></code>
36193613
<code><![CDATA[$routine['SPECIFIC_NAME']]]></code>
36203614
<code><![CDATA[$routine['SPECIFIC_NAME']]]></code>
@@ -3648,20 +3642,12 @@
36483642
<code><![CDATA[empty($_POST['editor_process_edit'])]]></code>
36493643
<code><![CDATA[empty($_POST['funcs'][$routine['item_param_name'][$i]])]]></code>
36503644
<code><![CDATA[empty($_POST['item_adjust_privileges'])]]></code>
3651-
<code><![CDATA[empty($_POST['item_comment'])]]></code>
36523645
<code><![CDATA[empty($_POST['item_returnlength'])]]></code>
36533646
<code><![CDATA[empty($_POST['item_returnlength'])]]></code>
36543647
<code><![CDATA[empty($_POST['item_returnopts_num'])]]></code>
36553648
<code><![CDATA[empty($_POST['item_returnopts_text'])]]></code>
3656-
<code><![CDATA[empty($itemDefiner)]]></code>
3657-
<code><![CDATA[empty($itemDefinition)]]></code>
3658-
<code><![CDATA[empty($itemName)]]></code>
36593649
<code><![CDATA[empty($itemParamDir[$i])]]></code>
3660-
<code><![CDATA[empty($itemParamLength)]]></code>
3661-
<code><![CDATA[empty($itemParamName)]]></code>
36623650
<code><![CDATA[empty($itemParamName[$i])]]></code>
3663-
<code><![CDATA[empty($itemParamType)]]></code>
3664-
<code><![CDATA[empty($itemSecurityType)]]></code>
36653651
<code><![CDATA[empty($routine['DTD_IDENTIFIER'])]]></code>
36663652
</RiskyTruthyFalsyComparison>
36673653
</file>

src/Controllers/Database/RoutinesController.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpMyAdmin\Controllers\InvocableController;
1010
use PhpMyAdmin\Current;
1111
use PhpMyAdmin\Database\Routines;
12+
use PhpMyAdmin\Database\RoutineType;
1213
use PhpMyAdmin\Dbal\DatabaseInterface;
1314
use PhpMyAdmin\DbTableExists;
1415
use PhpMyAdmin\Html\Generator;
@@ -55,7 +56,7 @@ public function __invoke(ServerRequest $request): Response
5556
{
5657
$this->response->addScriptFiles(['database/routines.js', 'sql.js']);
5758

58-
$type = $_REQUEST['type'] ?? null;
59+
$type = RoutineType::tryFrom($_REQUEST['type'] ?? '');
5960

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

@@ -104,7 +105,7 @@ public function __invoke(ServerRequest $request): Response
104105
}
105106

106107
if (! empty($_POST['editor_process_add']) || ! empty($_POST['editor_process_edit'])) {
107-
$output = $this->routines->handleRequestCreateOrEdit($userPrivileges, Current::$database);
108+
$output = $this->routines->handleRequestCreateOrEdit($userPrivileges, Current::$database, $request);
108109
if ($request->isAjax()) {
109110
if (! (Current::$message instanceof Message && Current::$message->isSuccess())) {
110111
$this->response->setRequestStatus(false);
@@ -116,7 +117,7 @@ public function __invoke(ServerRequest $request): Response
116117
$routines = Routines::getDetails(
117118
$this->dbi,
118119
Current::$database,
119-
$_POST['item_type'],
120+
RoutineType::tryFrom($request->getParsedBodyParamAsString('item_type', '')),
120121
$_POST['item_name'],
121122
);
122123
$routine = $routines[0];
@@ -451,10 +452,6 @@ public function __invoke(ServerRequest $request): Response
451452
}
452453
}
453454

454-
if (! isset($type) || ! in_array($type, ['FUNCTION', 'PROCEDURE'], true)) {
455-
$type = null;
456-
}
457-
458455
$totalNumRoutines = Routines::getRoutineCount($this->dbi, Current::$database, $type);
459456
$pageSize = $this->config->settings['MaxRoutineList'];
460457
$pos = (int) $request->getParam('pos');

src/Database/RoutineType.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace PhpMyAdmin\Database;
6+
7+
enum RoutineType: string
8+
{
9+
case Function = 'FUNCTION';
10+
case Procedure = 'PROCEDURE';
11+
}

0 commit comments

Comments
 (0)