]> git.joonet.de Git - adminer.git/commitdiff
Doc-comments: Fix type errors
authorJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 10:46:17 +0000 (11:46 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 11:47:09 +0000 (12:47 +0100)
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/include/adminer.inc.php
adminer/include/driver.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php
adminer/include/html.inc.php
plugins/drivers/elastic.php
plugins/drivers/mongo.php
plugins/drivers/simpledb.php

index d681dbfc0c0fc7afc6dde772f691c760af5f5420..0087035f572b7f6513e02163b990b0061a40d6dc 100644 (file)
@@ -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
index 97c5173c44e6c687a341a4b270a98fe5fc8c0142..77e20740b3aea275665142cc45078616271891bb 100644 (file)
@@ -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);
                        }
 
index ef6989ab7a63fa6fd710456d0c3bea7c3c43a267..709d387de8192964b3b5d1383d86c8cac73c489a 100644 (file)
@@ -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<string> */ public array $operators; // operators used in select, null for all operators
+       /** @var ?list<string> */ 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 '<p class="links">';
                $links = array("select" => lang('Select data'));
@@ -266,16 +266,16 @@ class Adminer {
        * @param Field $field single field returned from fields()
        * @return string|void null to create the default link
        */
-       function selectLink(string $val, array $field) {
+       function selectLink(?string $val, array $field) {
        }
 
        /** Value printed in select table
-       * @param string $val HTML-escaped value to print
-       * @param string $link link to foreign key
+       * @param ?string $val HTML-escaped value to print
+       * @param ?string $link link to foreign key
        * @param Field $field single field returned from fields()
        * @param string $original original value before applying editVal() and escaping
        */
-       function selectVal(string $val, string $link, array $field, string $original): string {
+       function selectVal(?string $val, ?string $link, array $field, ?string $original): string {
                $return = ($val === null ? "<i>NULL</i>"
                        : (preg_match("~char|binary|boolean~", $field["type"]) && !preg_match("~var~", $field["type"]) ? "<code>$val</code>"
                        : (preg_match('~json~', $field["type"]) ? "<code class='jush-js'>$val</code>"
@@ -290,7 +290,7 @@ class Adminer {
        /** Value conversion used in select and edit
        * @param Field $field single field returned from fields()
        */
-       function editVal(string $val, array $field): string {
+       function editVal(?string $val, array $field): ?string {
                return $val;
        }
 
@@ -616,7 +616,7 @@ class Adminer {
        * @param int $page index of page starting at zero
        * @return string empty string to use default query
        */
-       function selectQueryBuild(array $select, array $where, array $group, array $order, int $limit, int $page): string {
+       function selectQueryBuild(array $select, array $where, array $group, array $order, ?int $limit, ?int $page): string {
                return "";
        }
 
@@ -653,7 +653,7 @@ class Adminer {
        * @param Field[] $fields
        * @param mixed $row
        */
-       function editRowPrint(string $table, array $fields, $row, bool $update): void {
+       function editRowPrint(string $table, array $fields, $row, ?bool $update): void {
        }
 
        /** Functions displayed in edit form
@@ -688,7 +688,7 @@ class Adminer {
        * @param string $attrs attributes to use inside the tag
        * @return string custom input field or empty string for default
        */
-       function editInput(string $table, array $field, string $attrs, string $value): string {
+       function editInput(string $table, array $field, string $attrs, ?string $value): string {
                if ($field["type"] == "enum") {
                        return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
                                . ($field["null"] ? "<label><input type='radio'$attrs value=''" . ($value !== null || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "")
@@ -702,7 +702,7 @@ class Adminer {
        * @param string $table table name
        * @param Field $field single field from fields()
        */
-       function editHint(string $table, array $field, string $value): string {
+       function editHint(string $table, array $field, ?string $value): string {
                return "";
        }
 
@@ -710,7 +710,7 @@ class Adminer {
        * @param Field $field single field from fields()
        * @return string expression to use in a query
        */
-       function processInput(array $field, string $value, string $function = ""): string {
+       function processInput(array $field, string $value, ?string $function = ""): string {
                if ($function == "SQL") {
                        return $value; // SQL injection
                }
index 276a1284737445aad7c03c150827200ab40fcdae..2b2083bf31e2e3217a9889ce594ed66753a9b8c2 100644 (file)
@@ -74,7 +74,7 @@ abstract class SqlDriver {
        * @param bool $print whether to print the query
        * @return Result|false
        */
-       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) {
                global $adminer;
                $is_group = (count($group) < count($select));
                $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
@@ -190,7 +190,7 @@ abstract class SqlDriver {
        /** Convert value returned by database to actual value
        * @param Field $field
        */
-       function value(string $val, array $field): string {
+       function value(?string $val, array $field): ?string {
                return (method_exists($this->conn, 'value')
                        ? $this->conn->value($val, $field)
                        : (is_resource($val) ? stream_get_contents($val) : $val)
index e59c589d45cdd90c6c8ca513f77c05b628097685..dfbea8b95486e591d916c075cab3e18db937f0b8 100644 (file)
@@ -7,9 +7,10 @@ namespace Adminer;
 * @param Result $result
 * @param Db $connection2 connection to examine indexes
 * @param string[] $orgtables
+* @param int|numeric-string $limit
 * @return string[] $orgtables
 */
-function select($result, Db $connection2 = null, array $orgtables = array(), int $limit = 0): array {
+function select($result, Db $connection2 = null, array $orgtables = array(), $limit = 0): array {
        $links = array(); // colno => orgtable - create links from these columns
        $indexes = array(); // orgtable => array(column => colno) - primary keys
        $columns = array(); // orgtable => array(column => ) - not selected columns in primary key
@@ -138,7 +139,7 @@ function textarea(string $name, $value, int $rows = 10, int $cols = 80): void {
 /** Generate HTML <select> or <input> if $options are empty
 * @param string[] $options
 */
-function select_input(string $attrs, array $options, string $value = "", string $onchange = "", string $placeholder = ""): string {
+function select_input(string $attrs, array $options, ?string $value = "", string $onchange = "", string $placeholder = ""): string {
        $tag = ($options ? "select" : "input");
        return "<$tag$attrs" . ($options
                ? "><option value=''>$placeholder" . optionlist($options, $value, true) . "</select>"
@@ -218,7 +219,7 @@ function get_partitions_info(string $table): array {
 }
 
 /** Filter length value including enums */
-function process_length(string $length): string {
+function process_length(?string $length): string {
        global $driver;
        $enum_length = $driver->enumLength;
        return (preg_match("~^\\s*\\(?\\s*$enum_length(?:\\s*,\\s*$enum_length)*+\\s*\\)?\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches)
index 46dd2be70ab51ef0ca8bee3759e95110be882a91..d2093376efe5a46e72c1c63039b90dc463e8ca1e 100644 (file)
@@ -232,7 +232,7 @@ function get_rows(string $query, Db $connection2 = null, string $error = "<p cla
 * @param Index[] $indexes result of indexes()
 * @return string[]|void null if there is no unique identifier
 */
-function unique_array(array $row, array $indexes) {
+function unique_array(?array $row, array $indexes) {
        foreach ($indexes as $index) {
                if (preg_match("~PRIMARY|UNIQUE~", $index["type"])) {
                        $return = array();
@@ -456,7 +456,7 @@ function query_redirect(string $query, string $location, string $message, bool $
 
 class Queries {
        /** @var string[] */ static array $queries = array();
-       static float $start;
+       static float $start = 0;
 }
 
 /** Execute and remember query
@@ -671,7 +671,7 @@ function dump_csv(array $row): void {
 /** Apply SQL function
 * @param string $column escaped column identifier
 */
-function apply_sql_function(string $function, string $column): string {
+function apply_sql_function(?string $function, string $column): string {
        return ($function ? ($function == "unixepoch" ? "DATETIME($column, '$function')" : ($function == "count distinct" ? "COUNT(DISTINCT " : strtoupper("$function(")) . "$column)") : $column);
 }
 
@@ -818,7 +818,7 @@ function is_mail(?string $email): bool {
 }
 
 /** Check whether the string is URL address */
-function is_url(string $string): bool {
+function is_url(?string $string): bool {
        $domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component //! IDN
        return preg_match("~^(https?)://($domain?\\.)+$domain(:\\d+)?(/.*)?(\\?.*)?(#.*)?\$~i", $string); //! restrict path, query and fragment characters
 }
index 54225a0365bb939811d2087f08806cd293d048c6..1679d31d90d775fa324e1e9f82471515562c4607 100644 (file)
@@ -39,7 +39,7 @@ function target_blank(): string {
 }
 
 /** Escape for HTML */
-function h(string $string): string {
+function h(?string $string): string {
        return str_replace("\0", "&#0;", htmlspecialchars($string, ENT_QUOTES, 'utf-8'));
 }
 
@@ -51,7 +51,7 @@ function nl_br(string $string): string {
 /** Generate HTML checkbox
 * @param string|int $value
 */
-function checkbox(string $name, $value, bool $checked, string $label = "", string $onclick = "", string $class = "", string $labelled_by = ""): string {
+function checkbox(string $name, $value, ?bool $checked, string $label = "", string $onclick = "", string $class = "", string $labelled_by = ""): string {
        $return = "<input type='checkbox' name='$name' value='" . h($value) . "'"
                . ($checked ? " checked" : "")
                . ($labelled_by ? " aria-labelledby='$labelled_by'" : "")
@@ -91,7 +91,7 @@ function optionlist($options, $selected = null, bool $use_keys = false): string
 /** Generate HTML <select>
 * @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 "<select name='" . h($name) . "'"
                . ($labelled_by ? " aria-labelledby='$labelled_by'" : "")
                . ">" . optionlist($options, $value) . "</select>"
@@ -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 </div></fieldset>) */
-function print_fieldset(string $id, string $legend, bool $visible = false): void {
+/** Print header for hidden fieldset (close by </div></fieldset>)
+* @param bool $visible
+*/
+function print_fieldset(string $id, string $legend, $visible = false): void {
        echo "<fieldset><legend>";
        echo "<a href='#fieldset-$id'>$legend</a>";
        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
                : '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" . ($_GET["next"] ? "&next=" . urlencode($_GET["next"]) : "") : "")) . '">' . ($page + 1) . "</a>"
@@ -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[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
+               echo h($functions[""]) . "<td>" . $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))
                ) . '<td>';
-               $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(
index 7f99eaf71e0f28245f015192c22f42b44055da01..3fafcd8ef35d91a40e7846e97444bdcfad428795 100644 (file)
@@ -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);
index 96bda627ef0e36f1e0e90ce3d54b0fad4cba8151..0ee052fe1cf2ff46cd9e532c0740a66db484c001 100644 (file)
@@ -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)
index 82fa2452d48a521e806c39af2cd3b8f3b2fc9f54..1eb14d27264eb8afcc413c256f36f1907bbb98d3 100644 (file)
@@ -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);