diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b4b7eec579..98311c6fee 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1917,7 +1917,7 @@ parameters: - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 24 + count: 23 path: src/Controllers/Database/RoutinesController.php - @@ -1935,11 +1935,6 @@ parameters: count: 1 path: src/Controllers/Database/RoutinesController.php - - - message: "#^Parameter \\#1 \\$routine of method PhpMyAdmin\\\\Database\\\\Routines\\:\\:getRow\\(\\) expects array, mixed given\\.$#" - count: 2 - path: src/Controllers/Database/RoutinesController.php - - message: "#^Parameter \\#1 \\$string of function htmlentities expects string, mixed given\\.$#" count: 3 @@ -6995,31 +6990,6 @@ parameters: count: 9 path: src/Database/Routines.php - - - message: "#^Cannot access offset 'DTD_IDENTIFIER' on mixed\\.$#" - count: 1 - path: src/Database/Routines.php - - - - message: "#^Cannot access offset 'Db' on mixed\\.$#" - count: 1 - path: src/Database/Routines.php - - - - message: "#^Cannot access offset 'Definer' on mixed\\.$#" - count: 1 - path: src/Database/Routines.php - - - - message: "#^Cannot access offset 'Name' on mixed\\.$#" - count: 1 - path: src/Database/Routines.php - - - - message: "#^Cannot access offset 'Type' on mixed\\.$#" - count: 1 - path: src/Database/Routines.php - - message: "#^Cannot access offset 'value' on mixed\\.$#" count: 1 @@ -7132,7 +7102,7 @@ parameters: - message: "#^Parameter \\#1 \\$identifier of static method PhpMyAdmin\\\\Util\\:\\:backquote\\(\\) expects string\\|Stringable\\|null, mixed given\\.$#" - count: 10 + count: 9 path: src/Database/Routines.php - @@ -7157,7 +7127,7 @@ parameters: - message: "#^Parameter \\#1 \\$str of method PhpMyAdmin\\\\DatabaseInterface\\:\\:quoteString\\(\\) expects string, mixed given\\.$#" - count: 5 + count: 3 path: src/Database/Routines.php - @@ -7220,19 +7190,14 @@ parameters: count: 1 path: src/Database/Routines.php - - - message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" - count: 1 - path: src/Database/Routines.php - - message: "#^Parameter \\#3 \\$name of static method PhpMyAdmin\\\\Database\\\\Routines\\:\\:getFunctionDefinition\\(\\) expects string, mixed given\\.$#" - count: 3 + count: 2 path: src/Database/Routines.php - message: "#^Parameter \\#3 \\$name of static method PhpMyAdmin\\\\Database\\\\Routines\\:\\:getProcedureDefinition\\(\\) expects string, mixed given\\.$#" - count: 3 + count: 2 path: src/Database/Routines.php - @@ -13950,21 +13915,11 @@ parameters: count: 1 path: src/Server/Privileges.php - - - message: "#^Cannot access offset 'name' on mixed\\.$#" - count: 3 - path: src/Server/Privileges.php - - message: "#^Cannot access offset 'privs' on mixed\\.$#" count: 1 path: src/Server/Privileges.php - - - message: "#^Cannot access offset 'type' on mixed\\.$#" - count: 1 - path: src/Server/Privileges.php - - message: "#^Cannot access offset 0 on mixed\\.$#" count: 2 @@ -14010,11 +13965,6 @@ parameters: count: 1 path: src/Server/Privileges.php - - - message: "#^Method PhpMyAdmin\\\\Server\\\\Privileges\\:\\:getRoutineType\\(\\) should return string but returns mixed\\.$#" - count: 1 - path: src/Server/Privileges.php - - message: "#^Offset '@@old_passwords' does not exist on array\\|null\\.$#" count: 1 @@ -14137,7 +14087,7 @@ parameters: - message: "#^Parameter \\#1 \\$string of function mb_strtolower expects string, mixed given\\.$#" - count: 2 + count: 1 path: src/Server/Privileges.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index eb2a12f1c1..88f01a870e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1149,8 +1149,6 @@ - $item - $routine @@ -1185,8 +1183,6 @@ - $item - $routine @@ -4834,6 +4830,11 @@ DatabaseInterface::getInstance() + + + $returns + + Config::getInstance() @@ -4876,12 +4877,6 @@ - - - - - - $value $value $value @@ -4900,11 +4895,6 @@ $priv[5] $priv[6] $priv[7] - - - - - @@ -4966,7 +4956,6 @@ - $routine $string $value $value @@ -10607,7 +10596,6 @@ $passwordSetReal $privilege $realSqlQuery - $row $row @@ -10643,10 +10631,6 @@ - - - - @@ -10698,9 +10682,6 @@ $queries[] $queries[] $queries[] - $routine - $routine - $routines[] $row @@ -10714,7 +10695,6 @@ $value - string string|null @@ -10726,7 +10706,6 @@ $sqlQuery - diff --git a/resources/templates/database/routines/index.twig b/resources/templates/database/routines/index.twig index 1af4e8fa44..927bd75917 100644 --- a/resources/templates/database/routines/index.twig +++ b/resources/templates/database/routines/index.twig @@ -5,7 +5,7 @@
- {%- if items is not empty %} + {%- if has_any_routines %}
@@ -31,7 +31,7 @@
{%- endif %} - + {{ get_icon('b_routine_add', 'Create new routine'|trans) }} @@ -41,11 +41,11 @@
{{ get_hidden_inputs(db, table) }} -
+
{{ 'There are no routines to display.'|trans|notice }}
- +
diff --git a/src/Controllers/Database/RoutinesController.php b/src/Controllers/Database/RoutinesController.php index f67927ec16..820f2b44a8 100644 --- a/src/Controllers/Database/RoutinesController.php +++ b/src/Controllers/Database/RoutinesController.php @@ -145,7 +145,7 @@ class RoutinesController extends AbstractController 'new_row', $this->template->render('database/routines/row', $this->routines->getRow($routine)), ); - $this->response->addJSON('insert', ! empty($routine)); + $this->response->addJSON('insert', true); $this->response->addJSON('message', $output); $this->response->addJSON('tableType', 'routines'); @@ -484,7 +484,7 @@ class RoutinesController extends AbstractController $this->render('database/routines/index', [ 'db' => Current::$database, 'table' => Current::$table, - 'items' => $items, + 'has_any_routines' => $items !== [], 'rows' => $rows, 'has_privilege' => Util::currentUserHasPrivilege('CREATE ROUTINE', Current::$database, Current::$table), ]); diff --git a/src/Database/Routine.php b/src/Database/Routine.php new file mode 100644 index 0000000000..dc6370288f --- /dev/null +++ b/src/Database/Routine.php @@ -0,0 +1,15 @@ +type, + Util::backquote($routine->name), ); // this is for our purpose to decide whether to // show the edit link or not, so we need the DEFINER for the routine $where = 'ROUTINE_SCHEMA ' . Util::getCollateForIS() . '=' . $this->dbi->quoteString(Current::$database) - . ' AND SPECIFIC_NAME=' . $this->dbi->quoteString($routine['name']) - . ' AND ROUTINE_TYPE=' . $this->dbi->quoteString($routine['type']); + . ' AND SPECIFIC_NAME=' . $this->dbi->quoteString($routine->name) + . ' AND ROUTINE_TYPE=' . $this->dbi->quoteString($routine->type); $query = 'SELECT `DEFINER` FROM INFORMATION_SCHEMA.ROUTINES WHERE ' . $where . ';'; $routineDefiner = $this->dbi->fetchValue($query); @@ -1152,10 +1151,10 @@ class Routines // we will show a dialog to get values for these parameters, // otherwise we can execute it directly. - if ($routine['type'] === 'FUNCTION') { - $definition = self::getFunctionDefinition($this->dbi, Current::$database, $routine['name']); + if ($routine->type === 'FUNCTION') { + $definition = self::getFunctionDefinition($this->dbi, Current::$database, $routine->name); } else { - $definition = self::getProcedureDefinition($this->dbi, Current::$database, $routine['name']); + $definition = self::getProcedureDefinition($this->dbi, Current::$database, $routine->name); } $executeAction = ''; @@ -1166,12 +1165,12 @@ class Routines /** @var CreateStatement $stmt */ $stmt = $parser->statements[0]; - $params = Routine::getParameters($stmt); + $params = RoutineUtils::getParameters($stmt); if ($hasExecutePrivilege) { $executeAction = 'execute_routine'; for ($i = 0; $i < $params['num']; $i++) { - if ($routine['type'] === 'PROCEDURE' && $params['dir'][$i] === 'OUT') { + if ($routine->type === 'PROCEDURE' && $params['dir'][$i] === 'OUT') { continue; } @@ -1223,7 +1222,7 @@ class Routines * @param string|null $which PROCEDURE | FUNCTION or null for both * @param string $name name of the routine (to fetch a specific routine) * - * @return mixed[] information about PROCEDUREs or FUNCTIONs + * @return Routine[] */ public static function getDetails( DatabaseInterface $dbi, @@ -1261,14 +1260,9 @@ class Routines } $ret = []; + /** @var array{Name:string, Type:string, DTD_IDENTIFIER:string|null} $routine */ foreach ($routines as $routine) { - $ret[] = [ - 'db' => $routine['Db'], - 'name' => $routine['Name'], - 'type' => $routine['Type'], - 'definer' => $routine['Definer'], - 'returns' => $routine['DTD_IDENTIFIER'] ?? '', - ]; + $ret[] = new Routine($routine['Name'], $routine['Type'], $routine['DTD_IDENTIFIER'] ?? ''); } // Sort results by name diff --git a/src/Server/Privileges.php b/src/Server/Privileges.php index 371084a4ea..38cbb16035 100644 --- a/src/Server/Privileges.php +++ b/src/Server/Privileges.php @@ -1727,11 +1727,11 @@ class Privileges $routines = []; foreach ($routineData as $routine) { - if (in_array($routine['name'], $foundRows, true)) { + if (in_array($routine->name, $foundRows, true)) { continue; } - $routines[] = $routine['name']; + $routines[] = $routine->name; } $data['routines'] = $routines; @@ -3224,8 +3224,8 @@ class Privileges $routineName = mb_strtolower($routineName); foreach ($routineData as $routine) { - if (mb_strtolower($routine['name']) === $routineName) { - return $routine['type']; + if (mb_strtolower($routine->name) === $routineName) { + return $routine->type; } }