mirror of
https://github.com/vrana/adminer.git
synced 2025-08-06 14:46:36 +02:00
PHPStan: Fix level 3 errors
This commit is contained in:
@@ -505,7 +505,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
|
|
||||||
/** Get database collation
|
/** Get database collation
|
||||||
* @param string
|
* @param string
|
||||||
* @param list<string>[] result of collations()
|
* @param string[][] result of collations()
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function db_collation($db, $collations) {
|
function db_collation($db, $collations) {
|
||||||
@@ -705,7 +705,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get sorted grouped list of collations
|
/** Get sorted grouped list of collations
|
||||||
* @return list<string>[]
|
* @return string[][]
|
||||||
*/
|
*/
|
||||||
function collations() {
|
function collations() {
|
||||||
$return = array();
|
$return = array();
|
||||||
@@ -743,7 +743,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
/** Create database
|
/** Create database
|
||||||
* @param string
|
* @param string
|
||||||
* @param string
|
* @param string
|
||||||
* @return string
|
* @return Result
|
||||||
*/
|
*/
|
||||||
function create_database($db, $collation) {
|
function create_database($db, $collation) {
|
||||||
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " COLLATE " . q($collation) : ""));
|
return queries("CREATE DATABASE " . idf_escape($db) . ($collation ? " COLLATE " . q($collation) : ""));
|
||||||
@@ -813,7 +813,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
* @param string
|
* @param string
|
||||||
* @param string number
|
* @param string number
|
||||||
* @param string
|
* @param string
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||||
global $connection;
|
global $connection;
|
||||||
@@ -852,7 +852,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
/** Run commands to alter indexes
|
/** Run commands to alter indexes
|
||||||
* @param string escaped table name
|
* @param string escaped table name
|
||||||
* @param array{string, string, 'DROP'|list<string>} of ["index type", "name", ["column definition", ...]] or ["index type", "name", "DROP"]
|
* @param array{string, string, 'DROP'|list<string>} of ["index type", "name", ["column definition", ...]] or ["index type", "name", "DROP"]
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function alter_indexes($table, $alter) {
|
function alter_indexes($table, $alter) {
|
||||||
foreach ($alter as $key => $val) {
|
foreach ($alter as $key => $val) {
|
||||||
@@ -874,7 +874,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
|
|
||||||
/** Drop views
|
/** Drop views
|
||||||
* @param list<string>
|
* @param list<string>
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function drop_views($views) {
|
function drop_views($views) {
|
||||||
return queries("DROP VIEW " . implode(", ", array_map('Adminer\table', $views)));
|
return queries("DROP VIEW " . implode(", ", array_map('Adminer\table', $views)));
|
||||||
@@ -882,7 +882,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
|
|
||||||
/** Drop tables
|
/** Drop tables
|
||||||
* @param list<string>
|
* @param list<string>
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function drop_tables($tables) {
|
function drop_tables($tables) {
|
||||||
return queries("DROP TABLE " . implode(", ", array_map('Adminer\table', $tables)));
|
return queries("DROP TABLE " . implode(", ", array_map('Adminer\table', $tables)));
|
||||||
@@ -1014,7 +1014,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
"type" => strtolower($param[5]),
|
"type" => strtolower($param[5]),
|
||||||
"length" => preg_replace_callback("~$enum~s", 'Adminer\normalize_enum', $param[6]),
|
"length" => preg_replace_callback("~$enum~s", 'Adminer\normalize_enum', $param[6]),
|
||||||
"unsigned" => strtolower(preg_replace('~\s+~', ' ', trim("$param[8] $param[7]"))),
|
"unsigned" => strtolower(preg_replace('~\s+~', ' ', trim("$param[8] $param[7]"))),
|
||||||
"null" => 1,
|
"null" => true,
|
||||||
"full_type" => $param[4],
|
"full_type" => $param[4],
|
||||||
"inout" => strtoupper($param[1]),
|
"inout" => strtoupper($param[1]),
|
||||||
"collation" => strtolower($param[9]),
|
"collation" => strtolower($param[9]),
|
||||||
@@ -1073,7 +1073,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
/** Get approximate number of rows
|
/** Get approximate number of rows
|
||||||
* @param TableStatus
|
* @param TableStatus
|
||||||
* @param list<string>
|
* @param list<string>
|
||||||
* @return int or null if approximate number can't be retrieved
|
* @return numeric-string|void null if approximate number can't be retrieved
|
||||||
*/
|
*/
|
||||||
function found_rows($table_status, $where) {
|
function found_rows($table_status, $where) {
|
||||||
return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]);
|
return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]);
|
||||||
@@ -1222,7 +1222,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
|
|
||||||
/** Kill a process
|
/** Kill a process
|
||||||
* @param int
|
* @param int
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function kill_process($val) {
|
function kill_process($val) {
|
||||||
return queries("KILL " . number($val));
|
return queries("KILL " . number($val));
|
||||||
@@ -1236,7 +1236,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get maximum number of connections
|
/** Get maximum number of connections
|
||||||
* @return int
|
* @return numeric-string
|
||||||
*/
|
*/
|
||||||
function max_connections() {
|
function max_connections() {
|
||||||
return get_val("SELECT @@max_connections");
|
return get_val("SELECT @@max_connections");
|
||||||
|
@@ -789,7 +789,6 @@ ORDER BY SPECIFIC_NAME');
|
|||||||
if (preg_match("~ rows=([0-9]+)~", get_val("EXPLAIN SELECT * FROM " . idf_escape($table_status["Name"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")), $regs)) {
|
if (preg_match("~ rows=([0-9]+)~", get_val("EXPLAIN SELECT * FROM " . idf_escape($table_status["Name"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")), $regs)) {
|
||||||
return $regs[1];
|
return $regs[1];
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function types() {
|
function types() {
|
||||||
|
@@ -88,7 +88,7 @@ if (isset($_GET["sqlite"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function __destruct() {
|
function __destruct() {
|
||||||
return $this->result->finalize();
|
$this->result->finalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ abstract class SqlDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get structured types
|
/** Get structured types
|
||||||
* @return list<string>[] [$description => [$type, ...], ...]
|
* @return list<string>[]|list<string> [$description => [$type, ...], ...]
|
||||||
*/
|
*/
|
||||||
function structuredTypes() {
|
function structuredTypes() {
|
||||||
return array_map('array_keys', $this->types);
|
return array_map('array_keys', $this->types);
|
||||||
@@ -82,7 +82,7 @@ abstract class SqlDriver {
|
|||||||
* @param int result of $adminer->selectLimitProcess()
|
* @param int result of $adminer->selectLimitProcess()
|
||||||
* @param int index of page starting at zero
|
* @param int index of page starting at zero
|
||||||
* @param bool whether to print the query
|
* @param bool whether to print the query
|
||||||
* @return Result
|
* @return Result|false
|
||||||
*/
|
*/
|
||||||
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
||||||
global $adminer;
|
global $adminer;
|
||||||
@@ -109,7 +109,7 @@ abstract class SqlDriver {
|
|||||||
* @param string
|
* @param string
|
||||||
* @param string " WHERE ..."
|
* @param string " WHERE ..."
|
||||||
* @param int 0 or 1
|
* @param int 0 or 1
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function delete($table, $queryWhere, $limit = 0) {
|
function delete($table, $queryWhere, $limit = 0) {
|
||||||
$query = "FROM " . table($table);
|
$query = "FROM " . table($table);
|
||||||
@@ -122,7 +122,7 @@ abstract class SqlDriver {
|
|||||||
* @param string " WHERE ..."
|
* @param string " WHERE ..."
|
||||||
* @param int 0 or 1
|
* @param int 0 or 1
|
||||||
* @param string
|
* @param string
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") {
|
function update($table, $set, $queryWhere, $limit = 0, $separator = "\n") {
|
||||||
$values = array();
|
$values = array();
|
||||||
@@ -136,7 +136,7 @@ abstract class SqlDriver {
|
|||||||
/** Insert data into table
|
/** Insert data into table
|
||||||
* @param string
|
* @param string
|
||||||
* @param string[] escaped columns in keys, quoted data in values
|
* @param string[] escaped columns in keys, quoted data in values
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function insert($table, $set) {
|
function insert($table, $set) {
|
||||||
return queries("INSERT INTO " . table($table) . ($set
|
return queries("INSERT INTO " . table($table) . ($set
|
||||||
@@ -145,7 +145,7 @@ abstract class SqlDriver {
|
|||||||
) . $this->insertReturning($table));
|
) . $this->insertReturning($table));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get RETURNING clause for INSERT queries, PostgreSQL specific
|
/** Get RETURNING clause for INSERT queries (PostgreSQL specific)
|
||||||
* @param string
|
* @param string
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -157,28 +157,28 @@ abstract class SqlDriver {
|
|||||||
* @param string
|
* @param string
|
||||||
* @param list<string[]> of arrays with escaped columns in keys and quoted data in values
|
* @param list<string[]> of arrays with escaped columns in keys and quoted data in values
|
||||||
* @param int[] column names in keys
|
* @param int[] column names in keys
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function insertUpdate($table, $rows, $primary) {
|
function insertUpdate($table, $rows, $primary) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Begin transaction
|
/** Begin transaction
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function begin() {
|
function begin() {
|
||||||
return queries("BEGIN");
|
return queries("BEGIN");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Commit transaction
|
/** Commit transaction
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function commit() {
|
function commit() {
|
||||||
return queries("COMMIT");
|
return queries("COMMIT");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rollback transaction
|
/** Rollback transaction
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function rollback() {
|
function rollback() {
|
||||||
return queries("ROLLBACK");
|
return queries("ROLLBACK");
|
||||||
|
@@ -435,7 +435,7 @@ function normalize_enum($match) {
|
|||||||
* @param list<string>
|
* @param list<string>
|
||||||
* @param string
|
* @param string
|
||||||
* @param string
|
* @param string
|
||||||
* @return bool
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function grant($grant, $privileges, $columns, $on) {
|
function grant($grant, $privileges, $columns, $on) {
|
||||||
if (!$privileges) {
|
if (!$privileges) {
|
||||||
@@ -502,7 +502,7 @@ function create_trigger($on, $row) {
|
|||||||
|
|
||||||
/** Generate SQL query for creating routine
|
/** Generate SQL query for creating routine
|
||||||
* @param string "PROCEDURE" or "FUNCTION"
|
* @param string "PROCEDURE" or "FUNCTION"
|
||||||
* @param string[] result of routine()
|
* @param Routine result of routine()
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function create_routine($routine, $row) {
|
function create_routine($routine, $row) {
|
||||||
|
@@ -722,7 +722,7 @@ function table_status1($table, $fast = false) {
|
|||||||
|
|
||||||
/** Find out foreign keys for each column
|
/** Find out foreign keys for each column
|
||||||
* @param string
|
* @param string
|
||||||
* @return list<string>[] [$col => []]
|
* @return list<ForeignKey>[] [$col => []]
|
||||||
*/
|
*/
|
||||||
function column_foreign_keys($table) {
|
function column_foreign_keys($table) {
|
||||||
global $adminer;
|
global $adminer;
|
||||||
@@ -814,7 +814,7 @@ function get_temp_dir() {
|
|||||||
} else {
|
} else {
|
||||||
$filename = @tempnam("", ""); // @ - temp directory can be disabled by open_basedir
|
$filename = @tempnam("", ""); // @ - temp directory can be disabled by open_basedir
|
||||||
if (!$filename) {
|
if (!$filename) {
|
||||||
return false;
|
return '';
|
||||||
}
|
}
|
||||||
$return = dirname($filename);
|
$return = dirname($filename);
|
||||||
unlink($filename);
|
unlink($filename);
|
||||||
@@ -825,7 +825,7 @@ function get_temp_dir() {
|
|||||||
|
|
||||||
/** Open and exclusively lock a file
|
/** Open and exclusively lock a file
|
||||||
* @param string
|
* @param string
|
||||||
* @return resource or null for error
|
* @return resource|void null for error
|
||||||
*/
|
*/
|
||||||
function file_open_lock($filename) {
|
function file_open_lock($filename) {
|
||||||
if (is_link($filename)) {
|
if (is_link($filename)) {
|
||||||
@@ -873,7 +873,7 @@ function first($array) {
|
|||||||
|
|
||||||
/** Read password from file adminer.key in temporary directory or create one
|
/** Read password from file adminer.key in temporary directory or create one
|
||||||
* @param bool
|
* @param bool
|
||||||
* @return string or false if the file can not be created
|
* @return string|false false if the file can not be created
|
||||||
*/
|
*/
|
||||||
function password_file($create) {
|
function password_file($create) {
|
||||||
$filename = get_temp_dir() . "/adminer.key";
|
$filename = get_temp_dir() . "/adminer.key";
|
||||||
|
@@ -344,12 +344,12 @@ function input($field, $value, $function, $autofocus = false) {
|
|||||||
|
|
||||||
/** Process edit input field
|
/** Process edit input field
|
||||||
* @param Field one field from fields()
|
* @param Field one field from fields()
|
||||||
* @return string or false to leave the original value
|
* @return mixed false to leave the original value
|
||||||
*/
|
*/
|
||||||
function process_input($field) {
|
function process_input($field) {
|
||||||
global $adminer, $driver;
|
global $adminer, $driver;
|
||||||
if (stripos($field["default"], "GENERATED ALWAYS AS ") === 0) {
|
if (stripos($field["default"], "GENERATED ALWAYS AS ") === 0) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
$idf = bracket_escape($field["field"]);
|
$idf = bracket_escape($field["field"]);
|
||||||
$function = idx($_POST["function"], $idf);
|
$function = idx($_POST["function"], $idf);
|
||||||
|
@@ -75,7 +75,7 @@ function encrypt_string($str, $key) {
|
|||||||
/** Decipher
|
/** Decipher
|
||||||
* @param string binary cipher
|
* @param string binary cipher
|
||||||
* @param string
|
* @param string
|
||||||
* @return string plain-text password
|
* @return string|false plain-text password
|
||||||
*/
|
*/
|
||||||
function decrypt_string($str, $key) {
|
function decrypt_string($str, $key) {
|
||||||
if ($str == "") {
|
if ($str == "") {
|
||||||
|
@@ -15,7 +15,7 @@ function email_header($header) {
|
|||||||
* @param string
|
* @param string
|
||||||
* @param string
|
* @param string
|
||||||
* @param string
|
* @param string
|
||||||
* @param array{error?:list<int>, type?:list<string>, name?:list<string>}
|
* @param array{error?:list<int>, type?:list<string>, name?:list<string>, tmp_name?:list<string>}
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function send_mail($email, $subject, $message, $from = "", $files = array()) {
|
function send_mail($email, $subject, $message, $from = "", $files = array()) {
|
||||||
|
23
phpstan.neon
23
phpstan.neon
@@ -1,6 +1,13 @@
|
|||||||
parameters:
|
parameters:
|
||||||
level: 2
|
level: 3
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
|
# diagnose
|
||||||
|
- "~Adminer\\\\Db::~"
|
||||||
|
|
||||||
|
# need to fix
|
||||||
|
- "~^Function Adminer\\\\fields_from_edit\\(\\) should return~" # Mongo and SimpleDB
|
||||||
|
|
||||||
|
# not real problems
|
||||||
- identifier: include.fileNotFound # relative includes
|
- identifier: include.fileNotFound # relative includes
|
||||||
- identifier: includeOnce.fileNotFound # ./adminer-plugins.php
|
- identifier: includeOnce.fileNotFound # ./adminer-plugins.php
|
||||||
- "~^Function (set_magic_quotes_runtime|mysql_)~" # PHP < 7 functions
|
- "~^Function (set_magic_quotes_runtime|mysql_)~" # PHP < 7 functions
|
||||||
@@ -8,7 +15,7 @@ parameters:
|
|||||||
- "~^Variable \\$(adminer|connection|driver|drivers|error|HTTPS|LANG|langs|permanent|has_token|token|translations|VERSION) might not be defined~" # declared in bootstrap.inc.php
|
- "~^Variable \\$(adminer|connection|driver|drivers|error|HTTPS|LANG|langs|permanent|has_token|token|translations|VERSION) might not be defined~" # declared in bootstrap.inc.php
|
||||||
- "~^Comparison operation \"==\" between \\(array\\|float\\|int\\) and 1~" # false positive
|
- "~^Comparison operation \"==\" between \\(array\\|float\\|int\\) and 1~" # false positive
|
||||||
- "~OCI-?Lob~" # maybe include stub?
|
- "~OCI-?Lob~" # maybe include stub?
|
||||||
- "~Adminer\\\\Db::~" # diagnose!
|
|
||||||
paths:
|
paths:
|
||||||
- .
|
- .
|
||||||
phpVersion:
|
phpVersion:
|
||||||
@@ -16,10 +23,10 @@ parameters:
|
|||||||
max: 80499
|
max: 80499
|
||||||
checkMissingCallableSignature: true
|
checkMissingCallableSignature: true
|
||||||
typeAliases:
|
typeAliases:
|
||||||
TableStatus: "array{Name:string, Engine:string, Comment:string, Oid:int, Rows:int, Collation:string, Auto_increment:int, Data_length:int, Index_length:int, Data_free:int}"
|
TableStatus: "array{Name:string, Engine:string, Comment:string, Oid?:numeric-string, Rows:numeric-string, Collation:string, Auto_increment:numeric-string, Data_length:numeric-string, Index_length:numeric-string, Data_free:numeric-string, Create_options?:string, nspname?:string}"
|
||||||
Field: "array{field:string, full_type:string, type:string, length:int, unsigned:string, default:string, null:bool, auto_increment:bool, on_update:string, collation:string, privileges:int[], comment:string, primary:bool, generated:string}"
|
Field: "array{field:string, full_type:string, type:string, length:numeric-string, unsigned:string, default:?string, null:bool, auto_increment:bool, on_update:string, collation:string, privileges:int[], comment:string, primary:bool, generated:string, orig?:string, on_delete?:string, inout?:string}"
|
||||||
Index: "array{type:string, columns:list<string>, lengths:list<int>, descs:list<bool>}"
|
Index: "array{type:string, columns:list<string>, lengths:list<numeric-string>, descs:list<?bool>}"
|
||||||
ForeignKey: "array{db:string, ns:string, table:string, source:list<string>, target:list<string>, on_delete:string, on_update:string}"
|
ForeignKey: "array{db:string, ns?:string, table:string, source:list<string>, target:list<string>, on_delete:string, on_update:string}"
|
||||||
Trigger: "array{Trigger:string, Timing:string, Event:string, Of:string, Type:string, Statement:string}"
|
Trigger: "array{Trigger?:string, Timing?:string, Event?:string, Of?:string, Type?:string, Statement?:string}"
|
||||||
Routine: "array{fields:list<array{field:string, type:string, length:string, unsigned:string, null:bool, full_type:string, inout:string, collation:string}>, comment:string, returns:array, definition:string, language:string}"
|
Routine: "array{name?:string, fields:list<array{field:string, type:string, length:?string, unsigned:string, null:bool, full_type:string, inout:string, collation:string}>, comment:string, returns?:array, definition:string, language?:string}"
|
||||||
BackwardKey: "array{name:string, keys:string[][]}"
|
BackwardKey: "array{name:string, keys:string[][]}"
|
||||||
|
@@ -294,7 +294,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->conn->affected_rows;
|
return !!$this->conn->affected_rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertOperator($operator) {
|
function convertOperator($operator) {
|
||||||
@@ -528,7 +528,6 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function found_rows($table_status, $where) {
|
function found_rows($table_status, $where) {
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Alter type
|
/** Alter type
|
||||||
|
Reference in New Issue
Block a user