1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-18 20:31:19 +02:00

Doc-comments: Fix type errors

This commit is contained in:
Jakub Vrana
2025-03-28 13:15:14 +01:00
parent dc38a7ded3
commit 46f6a96c95
22 changed files with 60 additions and 64 deletions

View 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 "";
}

View 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

View 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;
}

View 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 = "";

View 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'>";

View 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);
}