diff --git a/adminer/call.inc.php b/adminer/call.inc.php index 67b0eab5..4bc37972 100644 --- a/adminer/call.inc.php +++ b/adminer/call.inc.php @@ -92,10 +92,9 @@ if ($in) {
', preg_replace('~\|~', '', preg_replace('~\|$~m', "", rtrim($s)))); } diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index d975b680..2f67494f 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -84,10 +84,9 @@ if (!defined('Adminer\DRIVER')) { } /** Set the client character set - * @param string $charset * @return bool */ - function set_charset($charset) { + function set_charset(string $charset) { if (function_exists('mysql_set_charset')) { if (mysql_set_charset($charset, $this->link)) { return true; @@ -129,9 +128,8 @@ if (!defined('Adminer\DRIVER')) { /** @var int */ private $offset = 0; /** Constructor - * @param resource $result */ - function __construct($result) { + function __construct(resource $result) { $this->result = $result; $this->num_rows = mysql_num_rows($result); } @@ -359,18 +357,16 @@ if (!defined('Adminer\DRIVER')) { /** Escape database identifier - * @param string $idf * @return string */ - function idf_escape($idf) { + function idf_escape(string $idf) { return "`" . str_replace("`", "``", $idf) . "`"; } /** Get escaped table name - * @param string $idf * @return string */ - function table($idf) { + function table(string $idf) { return idf_escape($idf); } @@ -378,7 +374,7 @@ if (!defined('Adminer\DRIVER')) { * @param array{string, string, string} $credentials [$server, $username, $password] * @return string|Db string for error */ - function connect($credentials) { + function connect(array $credentials) { global $drivers; $connection = new Db; if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { @@ -396,10 +392,9 @@ if (!defined('Adminer\DRIVER')) { } /** Get cached list of databases - * @param bool $flush * @return list */ - function get_databases($flush) { + function get_databases(bool $flush) { // SHOW DATABASES can take a very long time so it is cached $return = get_session("dbs"); if ($return === null) { @@ -415,32 +410,25 @@ if (!defined('Adminer\DRIVER')) { /** Formulate SQL query with limit * @param string $query everything after SELECT * @param string $where including WHERE - * @param int $limit - * @param int $offset - * @param string $separator * @return string */ - function limit($query, $where, $limit, $offset = 0, $separator = " ") { + function limit(string $query, string $where, int $limit, int $offset = 0, string $separator = " ") { return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } /** Formulate SQL modification query with limit 1 - * @param string $table * @param string $query everything after UPDATE or DELETE - * @param string $where - * @param string $separator * @return string */ - function limit1($table, $query, $where, $separator = "\n") { + function limit1(string $table, string $query, string $where, string $separator = "\n") { return limit($query, $where, 1, 0, $separator); } /** Get database collation - * @param string $db * @param string[][] $collations result of collations() * @return string */ - function db_collation($db, $collations) { + function db_collation(string $db, array $collations) { $return = null; $create = get_val("SHOW CREATE DATABASE " . idf_escape($db), 1); if (preg_match('~ COLLATE ([^ ]+)~', $create, $match)) { @@ -470,7 +458,7 @@ if (!defined('Adminer\DRIVER')) { * @param list $databases * @return int[] [$db => $tables] */ - function count_tables($databases) { + function count_tables(array $databases) { $return = array(); foreach ($databases as $db) { $return[$db] = count(get_vals("SHOW TABLES IN " . idf_escape($db))); @@ -479,11 +467,10 @@ if (!defined('Adminer\DRIVER')) { } /** Get table status - * @param string $name * @param bool $fast return only "Name", "Engine" and "Comment" fields * @return TableStatus[] */ - function table_status($name = "", $fast = false) { + function table_status(string $name = "", bool $fast = false) { $return = array(); foreach ( get_rows( @@ -512,7 +499,7 @@ if (!defined('Adminer\DRIVER')) { * @param TableStatus $table_status * @return bool */ - function is_view($table_status) { + function is_view(array $table_status) { return $table_status["Engine"] === null; } @@ -520,15 +507,14 @@ if (!defined('Adminer\DRIVER')) { * @param TableStatus $table_status result of table_status1() * @return bool */ - function fk_support($table_status) { + function fk_support(array $table_status) { return preg_match('~InnoDB|IBMDB2I' . (min_version(5.6) ? '|NDB' : '') . '~i', $table_status["Engine"]); } /** Get information about fields - * @param string $table * @return Field[] */ - function fields($table) { + function fields(string $table) { global $connection; $maria = ($connection->flavor == 'maria'); $return = array(); @@ -580,11 +566,9 @@ if (!defined('Adminer\DRIVER')) { } /** Get table indexes - * @param string $table - * @param ?Db $connection2 * @return Index[] */ - function indexes($table, $connection2 = null) { + function indexes(string $table, ?Db $connection2 = null) { $return = array(); foreach (get_rows("SHOW INDEX FROM " . table($table), $connection2) as $row) { $name = $row["Key_name"]; @@ -597,10 +581,9 @@ if (!defined('Adminer\DRIVER')) { } /** Get foreign keys in table - * @param string $table * @return ForeignKey[] */ - function foreign_keys($table) { + function foreign_keys(string $table) { global $driver; static $pattern = '(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")'; $return = array(); @@ -629,10 +612,9 @@ if (!defined('Adminer\DRIVER')) { } /** Get view SELECT - * @param string $name * @return array{select:string} */ - function view($name) { + function view(string $name) { return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)*\s+AS\s+~isU', '', get_val("SHOW CREATE VIEW " . table($name), 1))); } @@ -656,10 +638,9 @@ if (!defined('Adminer\DRIVER')) { } /** Find out if database is information_schema - * @param string $db * @return bool */ - function information_schema($db) { + function information_schema(string $db) { return ($db == "information_schema") || (min_version(5.5) && $db == "performance_schema"); } @@ -673,11 +654,9 @@ if (!defined('Adminer\DRIVER')) { } /** Create database - * @param string $db - * @param string $collation * @return Result */ - function create_database($db, $collation) { + function create_database(string $db, string $collation) { return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " COLLATE " . q($collation) : "")); } @@ -685,7 +664,7 @@ if (!defined('Adminer\DRIVER')) { * @param list $databases * @return bool */ - function drop_databases($databases) { + function drop_databases(array $databases) { $return = apply_queries("DROP DATABASE", $databases, 'Adminer\idf_escape'); restart_session(); set_session("dbs", null); @@ -694,10 +673,9 @@ if (!defined('Adminer\DRIVER')) { /** Rename database from DB * @param string $name new name - * @param string $collation * @return bool */ - function rename_database($name, $collation) { + function rename_database(string $name, string $collation) { $return = false; if (create_database($name, $collation)) { $tables = array(); @@ -740,14 +718,10 @@ if (!defined('Adminer\DRIVER')) { * @param string $name new name * @param list , string}> $fields of [$orig, $process_field, $after] * @param string[] $foreign - * @param string $comment - * @param string $engine - * @param string $collation * @param string $auto_increment number - * @param string $partitioning * @return Result|bool */ - function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $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) { @@ -786,7 +760,7 @@ if (!defined('Adminer\DRIVER')) { * @param list }> $alter of ["index type", "name", ["column definition", ...]] or ["index type", "name", "DROP"] * @return Result|bool */ - function alter_indexes($table, $alter) { + function alter_indexes(string $table, $alter) { $changes = array(); foreach ($alter as $val) { $changes[] = ($val[2] == "DROP" @@ -801,7 +775,7 @@ if (!defined('Adminer\DRIVER')) { * @param list $tables * @return bool */ - function truncate_tables($tables) { + function truncate_tables(array $tables) { return apply_queries("TRUNCATE TABLE", $tables); } @@ -809,7 +783,7 @@ if (!defined('Adminer\DRIVER')) { * @param list $views * @return Result|bool */ - function drop_views($views) { + function drop_views(array $views) { return queries("DROP VIEW " . implode(", ", array_map('Adminer\table', $views))); } @@ -817,17 +791,16 @@ if (!defined('Adminer\DRIVER')) { * @param list $tables * @return Result|bool */ - function drop_tables($tables) { + function drop_tables(array $tables) { return queries("DROP TABLE " . implode(", ", array_map('Adminer\table', $tables))); } /** Move tables to other schema * @param list $tables * @param list $views - * @param string $target * @return bool */ - function move_tables($tables, $views, $target) { + function move_tables(array $tables, array $views, string $target) { global $connection; $rename = array(); foreach ($tables as $table) { @@ -854,10 +827,9 @@ if (!defined('Adminer\DRIVER')) { /** Copy tables to other schema * @param list $tables * @param list $views - * @param string $target * @return bool */ - function copy_tables($tables, $views, $target) { + function copy_tables(array $tables, array $views, string $target) { queries("SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'"); foreach ($tables as $table) { $name = ($target == DB ? table("copy_$table") : idf_escape($target) . "." . table($table)); @@ -890,10 +862,9 @@ if (!defined('Adminer\DRIVER')) { /** Get information about trigger * @param string $name trigger name - * @param string $table * @return Trigger */ - function trigger($name, $table) { + function trigger(string $name, string $table) { if ($name == "") { return array(); } @@ -902,10 +873,9 @@ if (!defined('Adminer\DRIVER')) { } /** Get defined triggers - * @param string $table * @return array{string, string}[] */ - function triggers($table) { + function triggers(string $table) { $return = array(); foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_\\"))) as $row) { $return[$row["Trigger"]] = array($row["Timing"], $row["Event"]); @@ -925,11 +895,10 @@ if (!defined('Adminer\DRIVER')) { } /** Get information about stored routine - * @param string $name * @param 'FUNCTION'|'PROCEDURE' $type * @return Routine */ - function routine($name, $type) { + function routine(string $name, $type) { global $driver; $aliases = array("bool", "boolean", "integer", "double precision", "real", "dec", "numeric", "fixed", "national char", "national varchar"); $space = "(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)"; @@ -978,11 +947,10 @@ if (!defined('Adminer\DRIVER')) { } /** Get routine signature - * @param string $name * @param Routine $row result of routine() * @return string */ - function routine_id($name, $row) { + function routine_id(string $name, array $row) { return idf_escape($name); } @@ -995,11 +963,9 @@ if (!defined('Adminer\DRIVER')) { } /** Explain select - * @param Db $connection - * @param string $query * @return Result */ - function explain($connection, $query) { + function explain(Db $connection, string $query) { return $connection->query("EXPLAIN " . (min_version(5.1) && !min_version(5.7) ? "PARTITIONS " : "") . $query); } @@ -1008,17 +974,14 @@ if (!defined('Adminer\DRIVER')) { * @param list $where * @return numeric-string|null null if approximate number can't be retrieved */ - function found_rows($table_status, $where) { + function found_rows(array $table_status, array $where) { return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]); } /** Get SQL command to create table - * @param string $table - * @param bool $auto_increment - * @param string $style * @return string */ - function create_sql($table, $auto_increment, $style) { + function create_sql(string $table, bool $auto_increment, string $style) { $return = get_val("SHOW CREATE TABLE " . table($table), 1); if (!$auto_increment) { $return = preg_replace('~ AUTO_INCREMENT=\d+~', '', $return); //! skip comments @@ -1027,26 +990,23 @@ if (!defined('Adminer\DRIVER')) { } /** Get SQL command to truncate table - * @param string $table * @return string */ - function truncate_sql($table) { + function truncate_sql(string $table) { return "TRUNCATE " . table($table); } /** Get SQL command to change database - * @param string $database * @return string */ - function use_sql($database) { + function use_sql(string $database) { return "USE " . idf_escape($database); } /** Get SQL commands to create triggers - * @param string $table * @return string */ - function trigger_sql($table) { + function trigger_sql(string $table) { $return = ""; foreach (get_rows("SHOW TRIGGERS LIKE " . q(addcslashes($table, "%_\\")), null, "-- ") as $row) { $return .= "\nCREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . table($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n"; @@ -1079,7 +1039,7 @@ if (!defined('Adminer\DRIVER')) { * @param Field $field one element from fields() * @return string|void */ - function convert_field($field) { + function convert_field(array $field) { if (preg_match("~binary~", $field["type"])) { return "HEX(" . idf_escape($field["field"]) . ")"; } @@ -1096,7 +1056,7 @@ if (!defined('Adminer\DRIVER')) { * @param string $return SQL expression * @return string */ - function unconvert_field($field, $return) { + function unconvert_field(array $field, string $return) { if (preg_match("~binary~", $field["type"])) { $return = "UNHEX($return)"; } @@ -1114,7 +1074,7 @@ if (!defined('Adminer\DRIVER')) { * @param literal-string $feature "check|comment|copy|database|descidx|drop_col|dump|event|indexes|kill|materializedview|partitioning|privileges|procedure|processlist|routine|scheme|sequence|status|table|trigger|type|variables|view|view_trigger" * @return bool */ - function support($feature) { + function support(string $feature) { return !preg_match("~scheme|sequence|type|view_trigger|materializedview" . (min_version(8) ? "" : "|descidx" . (min_version(5.1) ? "" : "|event|partitioning")) . (min_version('8.0.16', '10.2.1') ? "" : "|check") . "~", $feature); } @@ -1122,7 +1082,7 @@ if (!defined('Adminer\DRIVER')) { * @param numeric-string $val * @return Result|bool */ - function kill_process($val) { + function kill_process(string $val) { return queries("KILL " . number($val)); } @@ -1150,10 +1110,9 @@ if (!defined('Adminer\DRIVER')) { } /** Get values of user defined type - * @param int $id * @return string */ - function type_values($id) { + function type_values(int $id) { return ""; } @@ -1172,11 +1131,9 @@ if (!defined('Adminer\DRIVER')) { } /** Set current schema - * @param string $schema - * @param Db $connection2 * @return bool */ - function set_schema($schema, $connection2 = null) { + function set_schema(string $schema, Db $connection2 = null) { return true; } } diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index 54211c27..da72e888 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -463,7 +463,7 @@ if (isset($_GET["sqlite"])) { * @param string $add_check CHECK constraint to add * @return bool */ - function recreate_table($table, $name, $fields, $originals, $foreign, $auto_increment = 0, $indexes = array(), $drop_check = "", $add_check = "") { + function recreate_table(string $table, string $name, array $fields, array $originals, array $foreign, int $auto_increment = 0, $indexes = array(), string $drop_check = "", string $add_check = "") { global $driver; if ($table != "") { if (!$fields) { diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index d9c1800b..d42d1cd5 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -28,10 +28,9 @@ class Adminer { } /** Get key used for permanent login - * @param bool $create * @return string cryptic string which gets combined with password or false in case of an error */ - function permanentLogin($create = false) { + function permanentLogin(bool $create = false) { return password_file($create); } @@ -43,10 +42,9 @@ class Adminer { } /** Get server name displayed in breadcrumbs - * @param string $server * @return string HTML code or null */ - function serverName($server) { + function serverName(string $server) { return h($server); } @@ -59,10 +57,9 @@ class Adminer { } /** Get cached list of databases - * @param bool $flush * @return list */ - function databases($flush = true) { + function databases(bool $flush = true) { return get_databases($flush); } @@ -97,7 +94,7 @@ class Adminer { * @param bool $dark dark CSS: false to disable, true to force, null to base on user preferences * @return bool true to link favicon.ico */ - function head($dark = null) { + function head(bool $dark = null) { // this is matched by compile.php echo "\n"; echo ($dark !== false ? "\n" : ""); @@ -137,21 +134,18 @@ class Adminer { } /** Get login form field - * @param string $name * @param string $heading HTML * @param string $value HTML * @return string */ - function loginFormField($name, $heading, $value) { + function loginFormField(string $name, string $heading, string $value) { return $heading . $value . "\n"; } /** Authorize the user - * @param string $login - * @param string $password * @return mixed true for success, string for error message, false for unknown error */ - function login($login, $password) { + function login(string $login, string $password) { if ($password == "") { return lang('Adminer does not support accessing a database without a password, more information.', target_blank()); } @@ -162,7 +156,7 @@ class Adminer { * @param TableStatus $tableStatus result of table_status1() * @return string HTML code, "" to ignore table */ - function tableName($tableStatus) { + function tableName(array $tableStatus) { return h($tableStatus["Name"]); } @@ -171,7 +165,7 @@ class Adminer { * @param int $order order of column in select * @return string HTML code, "" to ignore field */ - function fieldName($field, $order = 0) { + function fieldName(array $field, int $order = 0) { $type = $field["full_type"]; $comment = $field["comment"]; return '' . h($field["field"]) . ''; @@ -182,7 +176,7 @@ class Adminer { * @param string $set new item options, NULL for no new item * @return void */ - function selectLinks($tableStatus, $set = "") { + function selectLinks(array $tableStatus, string $set = "") { global $driver; echo ' '; $links = array("select" => lang('Select data')); @@ -210,19 +204,16 @@ class Adminer { } /** Get foreign keys for table - * @param string $table * @return ForeignKey[] same format as foreign_keys() */ - function foreignKeys($table) { + function foreignKeys(string $table) { return foreign_keys($table); } /** Find backward keys for table - * @param string $table - * @param string $tableName * @return BackwardKey[] */ - function backwardKeys($table, $tableName) { + function backwardKeys(string $table, string $tableName) { return array(); } @@ -231,16 +222,15 @@ class Adminer { * @param string[] $row * @return void */ - function backwardKeysPrint($backwardKeys, $row) { + function backwardKeysPrint(array $backwardKeys, array $row) { } /** Query printed in select before execution * @param string $query query to be executed * @param float $start start time of the query - * @param bool $failed * @return string */ - function selectQuery($query, $start, $failed = false) { + function selectQuery(string $query, float $start, bool $failed = false) { global $driver; $return = "
\n"; // required for IE9 inline edit if (!$failed && ($warnings = $driver->warnings())) { @@ -259,7 +249,7 @@ class Adminer { * @param string $query query to be executed * @return string escaped query to be printed */ - function sqlCommandQuery($query) { + function sqlCommandQuery(string $query) { return shorten_utf8(trim($query), 1000); } @@ -270,10 +260,9 @@ class Adminer { } /** Description of a row in a table - * @param string $table * @return string SQL expression, empty string for no description */ - function rowDescription($table) { + function rowDescription(string $table) { return ""; } @@ -282,7 +271,7 @@ class Adminer { * @param ForeignKey[] $foreignKeys * @return list*/ - function rowDescriptions($rows, $foreignKeys) { + function rowDescriptions(array $rows, array $foreignKeys) { return $rows; } @@ -291,7 +280,7 @@ class Adminer { * @param Field $field single field returned from fields() * @return string|void null to create the default link */ - function selectLink($val, $field) { + function selectLink(string $val, array $field) { } /** Value printed in select table @@ -301,7 +290,7 @@ class Adminer { * @param string $original original value before applying editVal() and escaping * @return string */ - function selectVal($val, $link, $field, $original) { + function selectVal(string $val, string $link, array $field, string $original) { $return = ($val === null ? "NULL" : (preg_match("~char|binary|boolean~", $field["type"]) && !preg_match("~var~", $field["type"]) ? " $val
" : (preg_match('~json~', $field["type"]) ? "$val
" @@ -314,11 +303,10 @@ class Adminer { } /** Value conversion used in select and edit - * @param string $val * @param Field $field single field returned from fields() * @return string */ - function editVal($val, $field) { + function editVal(string $val, array $field) { return $val; } @@ -327,7 +315,7 @@ class Adminer { * @param TableStatus $tableStatus * @return void */ - function tableStructurePrint($fields, $tableStatus = null) { + function tableStructurePrint(array $fields, array $tableStatus = null) { global $driver; echo "\n"; echo "\n"; @@ -358,7 +346,7 @@ class Adminer { * @param Index[] $indexes data about all indexes on a table * @return void */ - function tableIndexesPrint($indexes) { + function tableIndexesPrint(array $indexes) { echo "
\n"; foreach ($indexes as $name => $index) { ksort($index["columns"]); // enforce correct columns order @@ -379,7 +367,7 @@ class Adminer { * @param string[] $columns selectable columns * @return void */ - function selectColumnsPrint($select, $columns) { + function selectColumnsPrint(array $select, array $columns) { global $driver; print_fieldset("select", lang('Select'), $select); $i = 0; @@ -407,7 +395,7 @@ class Adminer { * @param Index[] $indexes * @return void */ - function selectSearchPrint($where, $columns, $indexes) { + function selectSearchPrint(array $where, array $columns, array $indexes) { print_fieldset("search", lang('Search'), $where); foreach ($indexes as $i => $index) { if ($index["type"] == "FULLTEXT") { @@ -443,7 +431,7 @@ class Adminer { * @param Index[] $indexes * @return void */ - function selectOrderPrint($order, $columns, $indexes) { + function selectOrderPrint(array $order, array $columns, array $indexes) { print_fieldset("sort", lang('Sort'), $order); $i = 0; foreach ((array) $_GET["order"] as $key => $val) { @@ -462,7 +450,7 @@ class Adminer { * @param string $limit result of selectLimitProcess() * @return void */ - function selectLimitPrint($limit) { + function selectLimitPrint(string $limit) { echo "