mirror of
https://github.com/vrana/adminer.git
synced 2025-08-07 15:16:44 +02:00
PHPStan: Fix level 4 errors
This commit is contained in:
@@ -444,7 +444,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
|
|
||||||
/** Connect to the database
|
/** Connect to the database
|
||||||
* @param array{string, string, string} [$server, $username, $password]
|
* @param array{string, string, string} [$server, $username, $password]
|
||||||
* @return mixed Db or string for error
|
* @return string|Db string for error
|
||||||
*/
|
*/
|
||||||
function connect($credentials) {
|
function connect($credentials) {
|
||||||
global $drivers;
|
global $drivers;
|
||||||
@@ -1073,47 +1073,12 @@ 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 numeric-string|void null if approximate number can't be retrieved
|
* @return numeric-string|null 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"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not used is MySQL but checked in compile.php:
|
|
||||||
/** Get user defined types
|
|
||||||
* @return string[] [$id => $name]
|
|
||||||
function types() {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get values of user defined type
|
|
||||||
* @param int
|
|
||||||
* @return string
|
|
||||||
function type_values($id) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get existing schemas
|
|
||||||
* @return list<string>
|
|
||||||
function schemas() {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get current schema
|
|
||||||
* @return string
|
|
||||||
function get_schema() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Set current schema
|
|
||||||
* @param string
|
|
||||||
* @param Db
|
|
||||||
* @return bool
|
|
||||||
function set_schema($schema, $connection2 = null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Get SQL command to create table
|
/** Get SQL command to create table
|
||||||
* @param string
|
* @param string
|
||||||
* @param bool
|
* @param bool
|
||||||
@@ -1241,4 +1206,44 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
function max_connections() {
|
function max_connections() {
|
||||||
return get_val("SELECT @@max_connections");
|
return get_val("SELECT @@max_connections");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not used is MySQL but checked in compile.php:
|
||||||
|
|
||||||
|
/** Get user defined types
|
||||||
|
* @return string[] [$id => $name]
|
||||||
|
*/
|
||||||
|
function types() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get values of user defined type
|
||||||
|
* @param int
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function type_values($id) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get existing schemas
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
function schemas() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get current schema
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function get_schema() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Set current schema
|
||||||
|
* @param string
|
||||||
|
* @param Db
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function set_schema($schema, $connection2 = null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -854,7 +854,7 @@ AND typelem = 0"
|
|||||||
}
|
}
|
||||||
$fields = fields($table);
|
$fields = fields($table);
|
||||||
|
|
||||||
if (!$status || empty($fields)) {
|
if (count($status) < 2 || empty($fields)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,6 +61,7 @@ function check_invalid_login() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/** @var array{int, int} */
|
||||||
$invalid = idx($invalids, $adminer->bruteForceKey(), array());
|
$invalid = idx($invalids, $adminer->bruteForceKey(), array());
|
||||||
$next_attempt = ($invalid[1] > 29 ? $invalid[0] - time() : 0); // allow 30 invalid attempts
|
$next_attempt = ($invalid[1] > 29 ? $invalid[0] - time() : 0); // allow 30 invalid attempts
|
||||||
if ($next_attempt > 0) { //! do the same with permanent login
|
if ($next_attempt > 0) { //! do the same with permanent login
|
||||||
|
@@ -124,7 +124,7 @@ function referencable_primary($self) {
|
|||||||
|
|
||||||
/** Print SQL <textarea> tag
|
/** Print SQL <textarea> tag
|
||||||
* @param string
|
* @param string
|
||||||
* @param string or array in which case [0] of every element is used
|
* @param string|list<array{string}>
|
||||||
* @param int
|
* @param int
|
||||||
* @param int
|
* @param int
|
||||||
* @return void
|
* @return void
|
||||||
|
@@ -174,7 +174,7 @@ function sid() {
|
|||||||
* @param string
|
* @param string
|
||||||
* @param string
|
* @param string
|
||||||
* @param string
|
* @param string
|
||||||
* @param string
|
* @param ?string
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function set_password($vendor, $server, $username, $password) {
|
function set_password($vendor, $server, $username, $password) {
|
||||||
@@ -185,7 +185,7 @@ function set_password($vendor, $server, $username, $password) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get password from session
|
/** Get password from session
|
||||||
* @return string or null for missing password or false for expired password
|
* @return string|false|null null for missing password, false for expired password
|
||||||
*/
|
*/
|
||||||
function get_password() {
|
function get_password() {
|
||||||
$return = get_session("pwds");
|
$return = get_session("pwds");
|
||||||
@@ -549,7 +549,7 @@ class Queries {
|
|||||||
|
|
||||||
/** Execute and remember query
|
/** Execute and remember query
|
||||||
* @param string end with ';' to use DELIMITER
|
* @param string end with ';' to use DELIMITER
|
||||||
* @return Result
|
* @return Result|bool
|
||||||
*/
|
*/
|
||||||
function queries($query) {
|
function queries($query) {
|
||||||
global $connection;
|
global $connection;
|
||||||
@@ -902,7 +902,7 @@ function rand_string() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Format value to use in select
|
/** Format value to use in select
|
||||||
* @param string
|
* @param string|string[]
|
||||||
* @param string
|
* @param string
|
||||||
* @param Field
|
* @param Field
|
||||||
* @param int
|
* @param int
|
||||||
@@ -945,7 +945,7 @@ function select_value($val, $link, $field, $text_length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Check whether the string is e-mail address
|
/** Check whether the string is e-mail address
|
||||||
* @param string
|
* @param ?string
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function is_mail($email) {
|
function is_mail($email) {
|
||||||
|
@@ -337,6 +337,7 @@ if (!$columns && support("table")) {
|
|||||||
$rank = 1;
|
$rank = 1;
|
||||||
foreach ($rows[0] as $key => $val) {
|
foreach ($rows[0] as $key => $val) {
|
||||||
if (!isset($unselected[$key])) {
|
if (!isset($unselected[$key])) {
|
||||||
|
/** @var array{fun?:string, col?:string} */
|
||||||
$val = idx($_GET["columns"], key($select)) ?: array();
|
$val = idx($_GET["columns"], key($select)) ?: array();
|
||||||
$field = $fields[$select ? ($val ? $val["col"] : current($select)) : $key];
|
$field = $fields[$select ? ($val ? $val["col"] : current($select)) : $key];
|
||||||
$name = ($field ? $adminer->fieldName($field, $rank) : ($val["fun"] ? "*" : h($key)));
|
$name = ($field ? $adminer->fieldName($field, $rank) : ($val["fun"] ? "*" : h($key)));
|
||||||
|
25
phpstan.neon
25
phpstan.neon
@@ -1,5 +1,5 @@
|
|||||||
parameters:
|
parameters:
|
||||||
level: 3
|
level: 4
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
# need to fix
|
# need to fix
|
||||||
- "~^Function Adminer\\\\fields_from_edit\\(\\) should return~" # Mongo and SimpleDB
|
- "~^Function Adminer\\\\fields_from_edit\\(\\) should return~" # Mongo and SimpleDB
|
||||||
@@ -12,10 +12,25 @@ parameters:
|
|||||||
- "~^Function (foreign_keys_sql|recreate_table) not found~" # defined by other drivers
|
- "~^Function (foreign_keys_sql|recreate_table) not found~" # defined by other drivers
|
||||||
- "~^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
|
||||||
- "~^Method Adminer\\\\Plugins::\\w+\\(\\) with return type void~" # we use the same pattern for all methods
|
- "~^Method Adminer\\\\Plugins::\\w+\\(\\) with return type void~" # we use the same pattern for all methods
|
||||||
- "~OCI-?Lob~" # maybe include stub?
|
- "~Call to function is_object\\(\\) with Adminer\\\\Db\\|string will always evaluate to false~" # is_object(Db) is true
|
||||||
|
- "~^Comparison operation \"==\" between \\(array\\|float\\|int\\) and 1~" # it thinks that $affected could be an array
|
||||||
|
|
||||||
# it probably doesn't like $ar[$key] instead of isset($ar[$key]) and thinks that $ar[$key] is always set
|
# it probably doesn't like $ar[$key] instead of isset($ar[$key]) and thinks that $ar[$key] is always set
|
||||||
- "~^Comparison operation \"==\" between \\(array\\|float\\|int\\) and 1~"
|
- identifier: identical.alwaysFalse
|
||||||
|
- identifier: notEqual.alwaysFalse
|
||||||
|
- identifier: notIdentical.alwaysTrue
|
||||||
|
- identifier: booleanNot.alwaysFalse
|
||||||
|
- identifier: booleanAnd.alwaysFalse
|
||||||
|
- identifier: booleanAnd.leftAlwaysTrue
|
||||||
|
- identifier: booleanAnd.rightAlwaysTrue
|
||||||
|
- identifier: booleanAnd.rightAlwaysFalse
|
||||||
|
- identifier: booleanOr.alwaysTrue
|
||||||
|
- identifier: booleanOr.leftAlwaysTrue
|
||||||
|
- identifier: ternary.alwaysTrue
|
||||||
|
- identifier: if.alwaysTrue
|
||||||
|
- identifier: while.alwaysTrue
|
||||||
|
- identifier: isset.offset
|
||||||
|
- identifier: deadCode.unreachable
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
- adminer/
|
- adminer/
|
||||||
@@ -34,8 +49,8 @@ parameters:
|
|||||||
max: 80499
|
max: 80499
|
||||||
checkMissingCallableSignature: true
|
checkMissingCallableSignature: true
|
||||||
typeAliases:
|
typeAliases:
|
||||||
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}"
|
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: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}"
|
Field: "array{field:?string, full_type:string, type:string, length:numeric-string, unsigned:string, default:?string, null:bool, auto_increment:bool, collation:string, privileges:int[], comment:string, primary:bool, generated:string, orig?:string, on_update:?string, on_delete?:string, inout?:string}"
|
||||||
Index: "array{type:string, columns:list<string>, lengths:list<numeric-string>, 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}"
|
||||||
|
Reference in New Issue
Block a user