From a9143ccbdcd37f7b904fc5fbac033e03f73585d9 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 28 Mar 2025 11:46:17 +0100 Subject: [PATCH] Doc-comments: Fix type errors --- adminer/drivers/mysql.inc.php | 6 +++--- adminer/drivers/pgsql.inc.php | 2 +- adminer/include/adminer.inc.php | 28 ++++++++++++++-------------- adminer/include/driver.inc.php | 4 ++-- adminer/include/editing.inc.php | 7 ++++--- adminer/include/functions.inc.php | 8 ++++---- adminer/include/html.inc.php | 23 +++++++++++++---------- plugins/drivers/elastic.php | 2 +- plugins/drivers/mongo.php | 2 +- plugins/drivers/simpledb.php | 2 +- 10 files changed, 44 insertions(+), 40 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index d681dbfc..0087035f 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -417,7 +417,7 @@ if (!defined('Adminer\DRIVER')) { /** Get database collation * @param string[][] $collations result of collations() */ - function db_collation(string $db, array $collations): string { + function db_collation(string $db, array $collations): ?string { $return = null; $create = get_val("SHOW CREATE DATABASE " . idf_escape($db), 1); if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) { @@ -698,7 +698,7 @@ if (!defined('Adminer\DRIVER')) { * @param string $auto_increment number * @return Result|bool */ - function alter_table(string $table, string $name, array $fields, array $foreign, string $comment, string $engine, string $collation, string $auto_increment, string $partitioning) { + function alter_table(string $table, string $name, array $fields, array $foreign, ?string $comment, string $engine, string $collation, string $auto_increment, string $partitioning) { global $connection; $alter = array(); foreach ($fields as $field) { @@ -928,7 +928,7 @@ if (!defined('Adminer\DRIVER')) { } /** Get last auto increment ID - * @param Result $result or true + * @param Result|bool $result */ function last_id($result): string { return get_val("SELECT LAST_INSERT_ID()"); // mysql_insert_id() truncates bigint diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 97c5173c..77e20740 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -48,7 +48,7 @@ if (isset($_GET["pgsql"])) { ); } - function value(string $val, array $field): string { + function value(?string $val, array $field): ?string { return ($field["type"] == "bytea" && $val !== null ? pg_unescape_bytea($val) : $val); } diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index ef6989ab..709d387d 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -4,7 +4,7 @@ namespace Adminer; // any method change in this file should be transferred to editor/include/adminer.inc.php and plugins.inc.php class Adminer { - /** @var list */ public array $operators; // operators used in select, null for all operators + /** @var ?list */ public ?array $operators = null; // operators used in select, null for all operators /** @visibility protected(set) */ public string $error = ''; // HTML /** Name in title and navigation @@ -42,7 +42,7 @@ class Adminer { /** Get server name displayed in breadcrumbs * @return string HTML code or null */ - function serverName(string $server): string { + function serverName(?string $server): string { return h($server); } @@ -164,9 +164,9 @@ class Adminer { /** Print links after select heading * @param TableStatus $tableStatus result of table_status1() - * @param string $set new item options, NULL for no new item + * @param ?string $set new item options, NULL for no new item */ - function selectLinks(array $tableStatus, string $set = ""): void { + function selectLinks(array $tableStatus, ?string $set = ""): void { global $driver; echo '

* @param string[] $options */ -function html_select(string $name, array $options, string $value = "", string $onchange = "", string $labelled_by = ""): string { +function html_select(string $name, array $options, ?string $value = "", string $onchange = "", string $labelled_by = ""): string { return "" @@ -115,8 +115,10 @@ function confirm(string $message = "", string $selector = "qsl('input')"): strin return script("$selector.onclick = () => confirm('" . ($message ? js_escape($message) : lang('Are you sure?')) . "');", ""); } -/** Print header for hidden fieldset (close by ) */ -function print_fieldset(string $id, string $legend, bool $visible = false): void { +/** Print header for hidden fieldset (close by ) +* @param bool $visible +*/ +function print_fieldset(string $id, string $legend, $visible = false): void { echo "

"; echo "$legend"; echo script("qsl('a').onclick = partial(toggle, 'fieldset-$id');", ""); @@ -135,7 +137,7 @@ function js_escape(string $string): string { } /** Generate page number for pagination */ -function pagination(int $page, int $current): string { +function pagination(int $page, ?int $current): string { return " " . ($page == $current ? $page + 1 : '' . ($page + 1) . "" @@ -210,8 +212,9 @@ function input(array $field, $value, string $function, bool $autofocus = false): $field["length"] = $enums; } echo $driver->unconvertFunction($field) . " "; + $table = $_GET["edit"] ?: $_GET["select"]; if ($field["type"] == "enum") { - echo h($functions[""]) . "" . $adminer->editInput($_GET["edit"], $field, $attrs, $value); + echo h($functions[""]) . "" . $adminer->editInput($table, $field, $attrs, $value); } else { $has_function = (in_array($function, $functions) || isset($functions[$function])); echo (count($functions) > 1 @@ -220,7 +223,7 @@ function input(array $field, $value, string $function, bool $autofocus = false): . script("qsl('select').onchange = functionChange;", "") : h(reset($functions)) ) . ''; - $input = $adminer->editInput($_GET["edit"], $field, $attrs, $value); // usage in call is without a table + $input = $adminer->editInput($table, $field, $attrs, $value); // usage in call is without a table if ($input != "") { echo $input; } elseif (preg_match('~bool~', $field["type"])) { @@ -263,7 +266,7 @@ function input(array $field, $value, string $function, bool $autofocus = false): . "$attrs>" ; } - echo $adminer->editHint($_GET["edit"], $field, $value); + echo $adminer->editHint($table, $field, $value); // skip 'original' $first = 0; foreach ($functions as $key => $val) { @@ -362,7 +365,7 @@ function on_help(string $command, int $side = 0): string { * @param Field[] $fields * @param mixed $row */ -function edit_form(string $table, array $fields, $row, bool $update): void { +function edit_form(string $table, array $fields, $row, ?bool $update): void { global $adminer, $error; $table_name = $adminer->tableName(table_status1($table, true)); page_header( diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php index 7f99eaf7..3fafcd8e 100644 --- a/plugins/drivers/elastic.php +++ b/plugins/drivers/elastic.php @@ -124,7 +124,7 @@ if (isset($_GET["elastic"])) { ); } - function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, int $page = 0, bool $print = false) { + function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) { $data = array(); if ($select != array("*")) { $data["fields"] = array_values($select); diff --git a/plugins/drivers/mongo.php b/plugins/drivers/mongo.php index 96bda627..0ee052fe 100644 --- a/plugins/drivers/mongo.php +++ b/plugins/drivers/mongo.php @@ -322,7 +322,7 @@ if (isset($_GET["mongo"])) { public $primary = "_id"; - function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, int $page = 0, bool $print = false) { + function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) { $select = ($select == array("*") ? array() : array_fill_keys($select, 1) diff --git a/plugins/drivers/simpledb.php b/plugins/drivers/simpledb.php index 82fa2452..1eb14d27 100644 --- a/plugins/drivers/simpledb.php +++ b/plugins/drivers/simpledb.php @@ -145,7 +145,7 @@ if (isset($_GET["simpledb"])) { return $return; } - function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, int $page = 0, bool $print = false) { + function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) { $connection = connection(); $connection->next = $_GET["next"]; $return = parent::select($table, $select, $where, $group, $order, $limit, $page, $print);