]> git.joonet.de Git - adminer.git/commitdiff
Doc-comments: Fix type errors
authorJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 12:15:14 +0000 (13:15 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 14:41:36 +0000 (15:41 +0100)
22 files changed:
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/adminer.inc.php
adminer/include/db.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php
adminer/include/html.inc.php
adminer/include/pdo.inc.php
adminer/select.inc.php
adminer/trigger.inc.php
adminer/user.inc.php
phpstan.neon
plugins/drivers/clickhouse.php
plugins/drivers/elastic.php
plugins/drivers/firebird.php
plugins/drivers/imap.php
plugins/drivers/mongo.php
plugins/drivers/simpledb.php
plugins/slugify.php

index d50004aed2f37fd54573701d4741bd7c1b2dfe6f..5263be2f4ee47247d4ff478512dc1805581e08f7 100644 (file)
@@ -116,11 +116,11 @@ if (isset($_GET["mssql"])) {
                                return $row;
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                return $this->convert(sqlsrv_fetch_array($this->result, SQLSRV_FETCH_ASSOC));
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                return $this->convert(sqlsrv_fetch_array($this->result, SQLSRV_FETCH_NUMERIC));
                        }
 
index b0c8ca5a34bb525c895c193f0d5932e5d567a21f..54004940dc430ff157620e943f0be8066f2fb4f9 100644 (file)
@@ -132,16 +132,16 @@ if (!defined('Adminer\DRIVER')) {
                        }
 
                        /** Fetch next row as associative array
-                       * @return array<?string>
+                       * @return array<?string>|false
                        */
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                return mysql_fetch_assoc($this->result);
                        }
 
                        /** Fetch next row as numbered array
-                       * @return list<?string>
+                       * @return list<?string>|false
                        */
-                       function fetch_row(): array {
+                       function fetch_row() {
                                return mysql_fetch_row($this->result);
                        }
 
@@ -623,7 +623,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** Find out if database is information_schema */
-       function information_schema(string $db): bool {
+       function information_schema(?string $db): bool {
                return ($db == "information_schema")
                        || (min_version(5.5) && $db == "performance_schema");
        }
@@ -951,7 +951,7 @@ if (!defined('Adminer\DRIVER')) {
        }
 
        /** Get SQL command to create table */
-       function create_sql(string $table, bool $auto_increment, string $style): string {
+       function create_sql(string $table, ?bool $auto_increment, string $style): string {
                $return = get_val("SHOW CREATE TABLE " . table($table), 1);
                if (!$auto_increment) {
                        $return = preg_replace('~ AUTO_INCREMENT=\d+~', '', $return); //! skip comments
index bc8ca5494a1703b8c9b80ce974094a5ace446f76..6c5940c87ffef7e253f79e3722d8714f6677c567 100644 (file)
@@ -79,11 +79,11 @@ if (isset($_GET["oracle"])) {
                                return $row;
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                return $this->convert(oci_fetch_assoc($this->result));
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                return $this->convert(oci_fetch_row($this->result));
                        }
 
index 77e20740b3aea275665142cc45078616271891bb..f2ee97219c50812fbeac095b1b4d705fa7e69175 100644 (file)
@@ -101,11 +101,11 @@ if (isset($_GET["pgsql"])) {
                                $this->num_rows = pg_num_rows($result);
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                return pg_fetch_assoc($this->result);
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                return pg_fetch_row($this->result);
                        }
 
index b6b7e6234086f287357bc7ce869959a370439ea4..58c37cc49f60adb4a6a86cd541ff009f360fe637 100644 (file)
@@ -48,11 +48,11 @@ if (isset($_GET["sqlite"])) {
                                $this->result = $result;
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                return $this->result->fetchArray(SQLITE3_ASSOC);
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                return $this->result->fetchArray(SQLITE3_NUM);
                        }
 
index 483ff56a1c314d1bdd79df0d38455dc6a4a80f1b..94292fae581b68d1cf01501d22f24892b6c44366 100644 (file)
@@ -46,7 +46,7 @@ class Adminer {
        }
 
        /** Identifier of selected database */
-       function database(): string {
+       function database(): ?string {
                // should be used everywhere instead of DB
                return DB;
        }
@@ -444,7 +444,7 @@ class Adminer {
        }
 
        /** Print text length box in select
-       * @param string $text_length result of selectLengthProcess()
+       * @param numeric-string $text_length result of selectLengthProcess()
        */
        function selectLengthPrint(string $text_length): void {
                if ($text_length !== null) {
@@ -600,10 +600,10 @@ class Adminer {
        }
 
        /** Process length box in select
-       * @return string number of characters to shorten texts, will be escaped
+       * @return numeric-string number of characters to shorten texts, will be escaped, empty string means unlimited
        */
        function selectLengthProcess(): string {
-               return (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
+               return (isset($_GET["text_length"]) ? "$_GET[text_length]" : "100");
        }
 
        /** Process extras in select form
@@ -691,11 +691,12 @@ class Adminer {
        }
 
        /** Get options to display edit field
+       * @param ?string $table null in call.inc.php
        * @param Field $field
        * @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> " : "")
@@ -706,9 +707,10 @@ class Adminer {
        }
 
        /** Get hint for edit field
+       * @param ?string $table null in call.inc.php
        * @param Field $field
        */
-       function editHint(string $table, array $field, ?string $value): string {
+       function editHint(?string $table, array $field, ?string $value): string {
                return "";
        }
 
index 3e0165647cd1f4c820330777aac8205a9ab919cc..1a609b7fac26f365713c43ba7f517bcd200a23f2 100644 (file)
@@ -5,7 +5,7 @@ namespace Adminer;
 // interfaces can include properties only since PHP 8.4
 abstract class SqlDb {
        public string $extension; // extension name
-       public string $flavor; // different vendor with the same API, e.g. MariaDB; usually stays empty
+       public string $flavor = ''; // different vendor with the same API, e.g. MariaDB; usually stays empty
        public string $server_info; // server version
        public int $affected_rows; // number of affected rows
        public string $info; // see https://php.net/mysql_info
index 626174c7e518a36be9f2a67c590feb4c96658c26..c53022180ae1dd67bb73d7f5745f457abf1471e1 100644 (file)
@@ -412,7 +412,7 @@ function normalize_enum(array $match): string {
 * @param list<string> $privileges
 * @return Result|bool
 */
-function grant(string $grant, array $privileges, string $columns, string $on) {
+function grant(string $grant, array $privileges, ?string $columns, string $on) {
        if (!$privileges) {
                return true;
        }
index 050b579ceb7bdfbf9c6004ff0b6d2e48fcd6b453..1ea224f1d30cdc883b67cc7177c7096e2bc436f5 100644 (file)
@@ -57,7 +57,7 @@ function escape_string(string $val): string {
 /** Get a possibly missing item from a possibly missing array
 * idx($row, $key) is better than $row[$key] ?? null because PHP will report error for undefined $row
 * @param ?mixed[] $array
-* @param string|int $key
+* @param array-key $key
 * @param mixed $default
 * @return mixed
 */
@@ -142,7 +142,7 @@ function sid(): bool {
 }
 
 /** Set password to session */
-function set_password(string $vendor, string $server, string $username, ?string $password): void {
+function set_password(string $vendor, ?string $server, string $username, ?string $password): void {
        $_SESSION["pwds"][$vendor][$server][$username] = ($_COOKIE["adminer_key"] && is_string($password)
                ? array(encrypt_string($password, $_COOKIE["adminer_key"]))
                : $password
@@ -391,7 +391,7 @@ function set_session(string $key, $val) {
 }
 
 /** Get authenticated URL */
-function auth_url(string $vendor, string $server, string $username, string $db = null): string {
+function auth_url(string $vendor, ?string $server, string $username, string $db = null): string {
        global $drivers;
        $uri = remove_from_uri(implode("|", array_keys($drivers))
                . "|username|ext|"
@@ -562,7 +562,7 @@ function repeat_pattern(string $pattern, int $length): string {
 }
 
 /** Check whether the string is in UTF-8 */
-function is_utf8(string $val): bool {
+function is_utf8(?string $val): bool {
        // don't print control chars except \t\r\n
        return (preg_match('~~u', $val) && !preg_match('~[\0-\x8\xB\xC\xE-\x1F]~', $val));
 }
@@ -771,9 +771,10 @@ function rand_string(): string {
 /** Format value to use in select
 * @param string|string[] $val
 * @param Field $field
+* @param ?numeric-string $text_length
 * @return string HTML
 */
-function select_value($val, string $link, array $field, int $text_length): string {
+function select_value($val, string $link, array $field, ?string $text_length): string {
        global $adminer;
        if (is_array($val)) {
                $return = "";
index c17fe1b23b90da398017874923545a2b501b9b01..9f3deda62d38aba973c2ca19db05249c77a2696e 100644 (file)
@@ -191,7 +191,7 @@ function enum_input(string $type, string $attrs, array $field, $value, string $e
 * @param Field|RoutineField $field
 * @param mixed $value
 */
-function input(array $field, $value, string $function, bool $autofocus = false): void {
+function input(array $field, $value, string $function, ?bool $autofocus = false): void {
        global $driver, $adminer;
        $name = h(bracket_escape($field["field"]));
        echo "<td class='function'>";
index cf9f2d19e70b81c7eb06dc834b32bf93f467131f..30e6dda9d6e5d98559aba5fafb46cf585bd93a65 100644 (file)
@@ -68,11 +68,11 @@ if (extension_loaded('pdo')) {
        class PdoResult extends \PDOStatement {
                public $_offset = 0, $num_rows;
 
-               function fetch_assoc(): array {
+               function fetch_assoc() {
                        return $this->fetch(\PDO::FETCH_ASSOC);
                }
 
-               function fetch_row(): array {
+               function fetch_row() {
                        return $this->fetch(\PDO::FETCH_NUM);
                }
 
index b6f7f03a203383d1b7ed8767a0718aed9fbca4b0..ae939debbdb7fef510cbfc87cd32e058b98dca0d 100644 (file)
@@ -13,7 +13,7 @@ $rights = array(); // privilege => 0
 $columns = array(); // selectable columns
 $search_columns = array(); // searchable columns
 $order_columns = array(); // searchable columns
-$text_length = null;
+$text_length = "";
 foreach ($fields as $key => $field) {
        $name = $adminer->fieldName($field);
        $name_plain = html_entity_decode(strip_tags($name), ENT_QUOTES);
index ed103d414bd0b26d4454c700a13f5f2ab137c1b7..7b7f5b03eaeade90c483b6e3aab152fe142d91e4 100644 (file)
@@ -2,7 +2,7 @@
 namespace Adminer;
 
 $TABLE = $_GET["trigger"];
-$name = $_GET["name"];
+$name = "$_GET[name]";
 $trigger_options = trigger_options();
 $row = (array) trigger($name, $TABLE) + array("Trigger" => $TABLE . "_bi");
 
index 3a70f3b2596105d3d95b1f052a7968bd17615300..a74b243105efbb93804d879403a5dd48d2cce077 100644 (file)
@@ -23,7 +23,7 @@ foreach ($privileges["Tables"] as $key => $val) {
 $new_grants = array();
 if ($_POST) {
        foreach ($_POST["objects"] as $key => $val) {
-               $new_grants[$val] = (array) $new_grants[$val] + (array) $_POST["grants"][$key];
+               $new_grants[$val] = (array) $new_grants[$val] + idx($_POST["grants"], $key, array());
        }
 }
 $grants = array();
index 4769dde5bdfe9eecfc8597feae90f75811861068..80deae6bb5ca865bc6ecca65f6a9765f7621e65d 100644 (file)
@@ -56,7 +56,7 @@ parameters:
                - adminer/sqlite.php
 
        phpVersion:
-               min: 70400
+               min: 70100
                max: 80499
 
        typeAliases:
index b7ca723a1b41d84354af09297ee8b0cd796ed10d..6b94e8cf1047c165386e6df372d8c263addd2f03 100644 (file)
@@ -91,13 +91,13 @@ if (isset($_GET["clickhouse"])) {
                                reset($this->rows);
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                $row = current($this->rows);
                                next($this->rows);
                                return $row === false ? false : array_combine($this->columns, $row);
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                $row = current($this->rows);
                                next($this->rows);
                                return $row;
index 3fafcd8ef35d91a40e7846e97444bdcfad428795..2eb7ad0c423dac115d46c7ec041e02b5cf33d898 100644 (file)
@@ -49,26 +49,19 @@ if (isset($_GET["elastic"])) {
                                return $return;
                        }
 
-                       /** Perform query relative to actual selected DB
-                        * @return array|false
-                        */
-                       function query(string $path, ?array $content = null, string $method = 'GET') {
+                       /** Perform query relative to actual selected DB */
+                       function query(string $query, bool $unbuffered = false) {
                                // Support for global search through all tables
-                               if ($path != "" && $path[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $path, $matches)) {
-                                       $driver = driver();
-
+                               if ($query[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $query, $matches)) {
                                        $where = explode(" AND ", $matches[2]);
-
-                                       return $driver->select($matches[1], array("*"), $where, array(), array(), $matches[3]);
+                                       return driver()->select($matches[1], array("*"), $where, array(), array(), $matches[3]);
                                }
-
-                               return $this->rootQuery($path, $content, $method);
                        }
 
                        function connect(string $server, string $username, string $password): bool {
                                preg_match('~^(https?://)?(.*)~', $server, $match);
                                $this->url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
-                               $return = $this->query('');
+                               $return = $this->rootQuery('');
                                if ($return) {
                                        $this->server_info = $return['version']['number'];
                                }
@@ -94,13 +87,13 @@ if (isset($_GET["elastic"])) {
                                reset($this->rows);
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                $return = current($this->rows);
                                next($this->rows);
                                return $return;
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                $row = $this->fetch_assoc();
                                return $row ? array_values($row) : false;
                        }
@@ -228,7 +221,7 @@ if (isset($_GET["elastic"])) {
                                $id = trim($parts[1]);
                                $query = "$type/$id";
 
-                               return $this->conn->query($query, $record, 'POST');
+                               return $this->conn->rootQuery($query, $record, 'POST');
                        }
 
                        return false;
@@ -245,7 +238,7 @@ if (isset($_GET["elastic"])) {
                                        unset($record[$key]);
                                }
                        }
-                       $response = $this->conn->query($query, $record, 'POST');
+                       $response = $this->conn->rootQuery($query, $record, 'POST');
                        if ($response == false) {
                                return false;
                        }
@@ -273,7 +266,7 @@ if (isset($_GET["elastic"])) {
 
                        foreach ($ids as $id) {
                                $query = "$table/_doc/$id";
-                               $response = $this->conn->query($query, null, 'DELETE');
+                               $response = $this->conn->rootQuery($query, null, 'DELETE');
                                if (isset($response['result']) && $response['result'] == 'deleted') {
                                        $this->conn->affected_rows++;
                                }
@@ -532,7 +525,7 @@ if (isset($_GET["elastic"])) {
                        $properties = array('properties' => $properties);
                }
 
-               return connection()->query("_mapping/$name", $properties, 'PUT');
+               return connection()->rootQuery("_mapping/$name", $properties, 'PUT');
        }
 
        /** Drop types
@@ -541,7 +534,7 @@ if (isset($_GET["elastic"])) {
        function drop_tables(array $tables): bool {
                $return = true;
                foreach ($tables as $table) { //! convert to bulk api
-                       $return = $return && connection()->query(urlencode($table), null, 'DELETE');
+                       $return = $return && connection()->rootQuery(urlencode($table), null, 'DELETE');
                }
 
                return $return;
index 75522b8702451e1e6b77a8c42531293271b786fe..36c86296e823f4e91b4bb769c81565930353bb51 100644 (file)
@@ -60,11 +60,11 @@ if (isset($_GET["firebird"])) {
                                // $this->num_rows = ibase_num_rows($result);
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                return ibase_fetch_assoc($this->result);
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                return ibase_fetch_row($this->result);
                        }
 
index 85357eae6bdb8c1ad9896668ef86c9b69c31b4a6..2063bcab53b9006e2723a52b31d2f846df3da503 100644 (file)
@@ -123,13 +123,13 @@ if (isset($_GET["imap"])) {
                                $this->fields = array_keys(idx($result, 0,  array()));
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                $row = current($this->result);
                                next($this->result);
                                return $row;
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                $row = $this->fetch_assoc();
                                return ($row ? array_values($row) : false);
                        }
index f9fca199307500abb49f8b317452e91a84e9edbf..d64527f7d8e581c64fc7383eca9346d8ef4a3eb4 100644 (file)
@@ -97,7 +97,7 @@ if (isset($_GET["mongo"])) {
                                $this->num_rows = count($this->rows);
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                $row = current($this->rows);
                                if (!$row) {
                                        return $row;
@@ -110,7 +110,7 @@ if (isset($_GET["mongo"])) {
                                return $return;
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                $return = $this->fetch_assoc();
                                if (!$return) {
                                        return $return;
index 1eb14d27264eb8afcc413c256f36f1907bbb98d3..1d6630c678d25911bcf5ca7eb22785ca86418e22 100644 (file)
@@ -76,7 +76,7 @@ if (isset($_GET["simpledb"])) {
                                return (is_object($element) && $element['encoding'] == 'base64' ? base64_decode($element) : (string) $element);
                        }
 
-                       function fetch_assoc(): array {
+                       function fetch_assoc() {
                                $row = current($this->rows);
                                if (!$row) {
                                        return $row;
@@ -89,7 +89,7 @@ if (isset($_GET["simpledb"])) {
                                return $return;
                        }
 
-                       function fetch_row(): array {
+                       function fetch_row() {
                                $return = $this->fetch_assoc();
                                if (!$return) {
                                        return $return;
index 2d5f99a47df66671c94e3502bbb5291ed071de13..07691f1dba8d6c2db490e0b7b3f3d4a82eb034d7 100644 (file)
@@ -20,7 +20,7 @@ class AdminerSlugify {
 
        function editInput($table, $field, $attrs, $value) {
                static $slugify;
-               if (!$_GET["select"] && !$_GET["where"]) {
+               if (!$_GET["select"] && !$_GET["where"] && $table) {
                        if ($slugify === null) {
                                $slugify = array();
                                $prev = null;