1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 14:46:36 +02:00

PHPStan: Fix level 4 errors

This commit is contained in:
Jakub Vrana
2025-03-26 18:32:45 +01:00
parent 53d5e7b60a
commit c78299a3f6
7 changed files with 73 additions and 51 deletions

View File

@@ -444,7 +444,7 @@ if (!defined('Adminer\DRIVER')) {
/** Connect to the database
* @param array{string, string, string} [$server, $username, $password]
* @return mixed Db or string for error
* @return string|Db string for error
*/
function connect($credentials) {
global $drivers;
@@ -1073,47 +1073,12 @@ if (!defined('Adminer\DRIVER')) {
/** Get approximate number of rows
* @param TableStatus
* @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) {
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
* @param string
* @param bool
@@ -1241,4 +1206,44 @@ if (!defined('Adminer\DRIVER')) {
function 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;
}
}

View File

@@ -854,7 +854,7 @@ AND typelem = 0"
}
$fields = fields($table);
if (!$status || empty($fields)) {
if (count($status) < 2 || empty($fields)) {
return false;
}

View File

@@ -61,6 +61,7 @@ function check_invalid_login() {
break;
}
}
/** @var array{int, int} */
$invalid = idx($invalids, $adminer->bruteForceKey(), array());
$next_attempt = ($invalid[1] > 29 ? $invalid[0] - time() : 0); // allow 30 invalid attempts
if ($next_attempt > 0) { //! do the same with permanent login

View File

@@ -124,7 +124,7 @@ function referencable_primary($self) {
/** Print SQL <textarea> tag
* @param string
* @param string or array in which case [0] of every element is used
* @param string|list<array{string}>
* @param int
* @param int
* @return void

View File

@@ -174,7 +174,7 @@ function sid() {
* @param string
* @param string
* @param string
* @param string
* @param ?string
* @return void
*/
function set_password($vendor, $server, $username, $password) {
@@ -185,7 +185,7 @@ function set_password($vendor, $server, $username, $password) {
}
/** 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() {
$return = get_session("pwds");
@@ -549,7 +549,7 @@ class Queries {
/** Execute and remember query
* @param string end with ';' to use DELIMITER
* @return Result
* @return Result|bool
*/
function queries($query) {
global $connection;
@@ -902,7 +902,7 @@ function rand_string() {
}
/** Format value to use in select
* @param string
* @param string|string[]
* @param string
* @param Field
* @param int
@@ -945,7 +945,7 @@ function select_value($val, $link, $field, $text_length) {
}
/** Check whether the string is e-mail address
* @param string
* @param ?string
* @return bool
*/
function is_mail($email) {

View File

@@ -337,6 +337,7 @@ if (!$columns && support("table")) {
$rank = 1;
foreach ($rows[0] as $key => $val) {
if (!isset($unselected[$key])) {
/** @var array{fun?:string, col?:string} */
$val = idx($_GET["columns"], key($select)) ?: array();
$field = $fields[$select ? ($val ? $val["col"] : current($select)) : $key];
$name = ($field ? $adminer->fieldName($field, $rank) : ($val["fun"] ? "*" : h($key)));

View File

@@ -1,10 +1,10 @@
parameters:
level: 3
level: 4
ignoreErrors:
# need to fix
- "~^Function Adminer\\\\fields_from_edit\\(\\) should return~" # Mongo and SimpleDB
- "~^Function Adminer\\\\explain\\(\\) should return Adminer\\\\Result~" # mysqli_result
# not real problems
- identifier: include.fileNotFound # relative includes
- identifier: includeOnce.fileNotFound # ./adminer-plugins.php
@@ -12,10 +12,25 @@ parameters:
- "~^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
- "~^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
- "~^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:
- adminer/
@@ -28,14 +43,14 @@ parameters:
- adminer/drivers/oracle.inc.php
- adminer/drivers/pgsql.inc.php
- adminer/drivers/sqlite.inc.php
phpVersion:
min: 70100
max: 80499
checkMissingCallableSignature: true
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}"
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}"
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, 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>}"
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}"