1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-05 22:27:24 +02:00

PHPStan: Fix level 6 errors

This commit is contained in:
Jakub Vrana
2025-03-26 21:06:01 +01:00
parent c96894ecd4
commit d3b53d9d9c
14 changed files with 114 additions and 51 deletions

View File

@@ -91,9 +91,14 @@ if ($in) {
<pre>
<?php
/** Format string as table row
* @param string
* @return string HTML
*/
function pre_tr($s) {
return preg_replace('~^~m', '<tr>', preg_replace('~\|~', '<td>', preg_replace('~\|$~m', "", rtrim($s))));
}
$table = '(\+--[-+]+\+\n)';
$row = '(\| .* \|\n)';
echo preg_replace_callback(

View File

@@ -61,16 +61,16 @@ if (!defined('Adminer\DRIVER')) {
} elseif (extension_loaded("mysql") && !((ini_bool("sql.safe_mode") || ini_bool("mysql.allow_local_infile")) && extension_loaded("pdo_mysql"))) {
class Db {
public
$extension = "MySQL", ///< @var string extension name
$flavor = '', ///< @var string different vendor with the same API, e.g. MariaDB, usually stays empty
$server_info, ///< @var string server version
$affected_rows, ///< @var int number of affected rows
$info, ///< @var string see https://php.net/mysql_info
$errno, ///< @var int last error code
$error ///< @var string last error message
;
private $link, $result;
/** @var string */ public $extension = "MySQL"; // extension name
/** @var string */ public $flavor = ''; // different vendor with the same API; e.g. MariaDB; usually stays empty
/** @var string */ public $server_info; // server version
/** @var int */ public $affected_rows; // number of affected rows
/** @var string */ public $info; // see https://php.net/mysql_info
/** @var int */ public $errno; // last error code
/** @var string */ public $error; // last error message
/** @var \mysqli */ private $link;
/** @var Result */ private $result;
/** Connect to server
* @param string
@@ -132,7 +132,7 @@ if (!defined('Adminer\DRIVER')) {
/** Send query
* @param string
* @param bool
* @return mixed bool or Result
* @return Result|bool
*/
function query($query, $unbuffered = false) {
$result = @($unbuffered ? mysql_unbuffered_query($query, $this->link) : mysql_query($query, $this->link)); // @ - mute mysql.trace_mode
@@ -152,7 +152,7 @@ if (!defined('Adminer\DRIVER')) {
/** Send query with more resultsets
* @param string
* @return bool
* @return Result|bool
*/
function multi_query($query) {
return $this->result = $this->query($query);
@@ -185,8 +185,9 @@ if (!defined('Adminer\DRIVER')) {
}
class Result {
public $num_rows; ///< @var int number of rows in the result
private $result, $offset = 0;
/** @var int */ public $num_rows; // number of rows in the result
/** @var resource */ private $result;
/** @var int */ private $offset = 0;
/** Constructor
* @param resource
@@ -286,13 +287,13 @@ if (!defined('Adminer\DRIVER')) {
class Driver extends SqlDriver {
static $possibleDrivers = array("MySQLi", "MySQL", "PDO_MySQL");
static $jush = "sql"; ///< @var string JUSH identifier
/** @var list<string> */ static $possibleDrivers = array("MySQLi", "MySQL", "PDO_MySQL");
/** @var string */ static $jush = "sql"; // JUSH identifier
public $unsigned = array("unsigned", "zerofill", "unsigned zerofill");
public $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "REGEXP", "IN", "FIND_IN_SET", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL", "SQL");
public $functions = array("char_length", "date", "from_unixtime", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper");
public $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
/** @var list<string> */ public $unsigned = array("unsigned", "zerofill", "unsigned zerofill");
/** @var list<string> */ public $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "REGEXP", "IN", "FIND_IN_SET", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL", "SQL");
/** @var list<string> */ public $functions = array("char_length", "date", "from_unixtime", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper");
/** @var list<string> */ public $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
function __construct($connection) {
parent::__construct($connection);

View File

@@ -4,8 +4,8 @@ namespace Adminer;
// any method change in this file should be transferred to editor/include/adminer.inc.php and plugins.inc.php
class Adminer {
public $operators; ///< @var list<string> operators used in select, null for all operators
public $error = ''; ///< @var string @visibility protected(set) string HTML
/** @var list<string> */ public $operators; // operators used in select, null for all operators
/** @var string @visibility protected(set) */ public $error = ''; // HTML
/** Name in title and navigation
* @return string HTML code
@@ -264,6 +264,7 @@ class Adminer {
}
/** Print HTML code just before the Execute button in SQL command
* @return void
*/
function sqlPrintAfter() {
}
@@ -689,7 +690,7 @@ class Adminer {
/** Print before edit form
* @param string
* @param array[]
* @param Field[]
* @param mixed
* @param bool
* @return void
@@ -1052,6 +1053,7 @@ class Adminer {
/** Set up syntax highlight for code and <textarea>
* @param TableStatus[] result of table_status('', true)
* @return void
*/
function syntaxHighlighting($tables) {
global $connection;

View File

@@ -17,6 +17,7 @@ if ($_COOKIE["adminer_permanent"]) {
}
}
/** @return void */
function add_invalid_login() {
global $adminer;
$base = get_temp_dir() . "/adminer.invalid";
@@ -50,6 +51,7 @@ function add_invalid_login() {
file_write_unlock($fp, serialize($invalids));
}
/** @return void */
function check_invalid_login() {
global $adminer;
$invalids = array();
@@ -113,6 +115,7 @@ if ($auth) {
}
}
/** @return void */
function unset_permanent() {
global $permanent;
foreach ($permanent as $key => $val) {

View File

@@ -3,6 +3,7 @@ namespace Adminer;
// coverage is used in tests and removed in compilation
if (extension_loaded("xdebug") && file_exists(sys_get_temp_dir() . "/adminer.coverage")) {
/** @return void */
function save_coverage() {
$coverage_filename = sys_get_temp_dir() . "/adminer.coverage";
$coverage = unserialize(file_get_contents($coverage_filename));

View File

@@ -23,20 +23,20 @@ function get_driver($id) {
}
abstract class SqlDriver {
static $possibleDrivers = array(); ///< @var list<string>
static $jush; ///< @var string JUSH identifier
/** @var list<string> */ static $possibleDrivers = array();
/** @var string */ static $jush; // JUSH identifier
protected $conn; ///< @var Db
protected $types = array(); ///< @var int[][] [$group => [$type => $maximum_unsigned_length, ...], ...]
public $editFunctions = array(); ///< @var array of ["$type|$type2" => "$function/$function2"] functions used in editing, [0] - edit and insert, [1] - edit only
public $unsigned = array(); ///< @var list<string> number variants
public $operators = array(); ///< @var list<string> operators used in select
public $functions = array(); ///< @var list<string> functions used in select
public $grouping = array(); ///< @var list<string> grouping functions used in select
public $onActions = "RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT"; ///< @var string used in foreign_keys()
public $inout = "IN|OUT|INOUT"; ///< @var string used in routines
public $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'"; ///< @var string regular expression for parsing enum lengths
public $generated = array(); ///< @var list<string> allowed types of generated columns
/** @var Db */ protected $conn;
/** @var int[][] */ protected $types = array(); // [$group => [$type => $maximum_unsigned_length, ...], ...]
/** @var array{0?:string[], 1?:string[]} */ public $editFunctions = array(); // of ["$type|$type2" => "$function/$function2"] functions used in editing, [0] - edit and insert, [1] - edit only
/** @var list<string> */ public $unsigned = array(); // number variants
/** @var list<string> */ public $operators = array(); // operators used in select
/** @var list<string> */ public $functions = array(); // functions used in select
/** @var list<string> */ public $grouping = array(); // grouping functions used in select
/** @var string */ public $onActions = "RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT"; // used in foreign_keys()
/** @var string */ public $inout = "IN|OUT|INOUT"; // used in routines
/** @var string */ public $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'"; // regular expression for parsing enum lengths
/** @var list<string> */ public $generated = array(); // allowed types of generated columns
/** Create object for performing database operations
* @param Db

View File

@@ -67,7 +67,7 @@ function escape_string($val) {
/** 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 ?array
* @param ?mixed[]
* @param string|int
* @param mixed
* @return mixed
@@ -543,8 +543,8 @@ function query_redirect($query, $location, $message, $redirect = true, $execute
}
class Queries {
static $queries = array();
static $start;
/** @var string[] */ static $queries = array();
/** @var float */ static $start;
}
/** Execute and remember query
@@ -846,6 +846,7 @@ function file_open_lock($filename) {
/** Write and unlock a file
* @param resource
* @param string
* @return void
*/
function file_write_unlock($fp, $data) {
rewind($fp);
@@ -856,6 +857,7 @@ function file_write_unlock($fp, $data) {
/** Unlock and close a file
* @param resource
* @return void
*/
function file_unlock($fp) {
flock($fp, LOCK_UN);
@@ -863,8 +865,8 @@ function file_unlock($fp) {
}
/** Get first element of an array
* @param array
* @return mixed or false if not found
* @param mixed[]
* @return mixed if not found
*/
function first($array) {
// reset(f()) triggers a notice
@@ -1029,6 +1031,10 @@ function verify_token() {
}
// used in compiled version
/**
* @param string
* @return string
*/
function lzw_decompress($binary) {
// convert binary string to codes
$dictionary_count = 256;

View File

@@ -197,7 +197,7 @@ function pagination($page, $current) {
}
/** Print hidden fields
* @param array
* @param mixed[]
* @param list<string>
* @param string
* @return bool

View File

@@ -92,6 +92,7 @@ function lang($idf, $number = null) {
return vsprintf($format, $args);
}
/** @return void */
function switch_lang() {
global $LANG, $langs;
echo "<form action='' method='post'>\n<div id='lang'>";

View File

@@ -2,7 +2,7 @@
namespace Adminer;
class Plugins extends Adminer {
public $plugins; ///< @var list<object> @visibility protected(set)
/** @var list<object> @visibility protected(set) */ public $plugins;
/** Register plugins
* @param ?list<object> object instances or null to autoload plugins from adminer-plugins/
@@ -42,10 +42,20 @@ class Plugins extends Adminer {
$this->plugins = $plugins;
}
/**
* @param literal-string
* @param mixed[]
* @return mixed
*/
private function callParent($function, $args) {
return call_user_func_array(array('parent', $function), $args);
}
/**
* @param literal-string
* @param mixed[]
* @return mixed
*/
private function applyPlugin($function, $params) {
$args = array();
foreach ($params as $key => $val) {
@@ -63,6 +73,11 @@ class Plugins extends Adminer {
return $this->callParent($function, $args);
}
/**
* @param literal-string
* @param mixed[]
* @return mixed
*/
private function appendPlugin($function, $args) {
$return = $this->callParent($function, $args);
foreach ($this->plugins as $plugin) {

View File

@@ -2,18 +2,23 @@
namespace Adminer;
class TmpFile {
private $handler;
public $size; ///< @visibility protected(set)
/** @var resource */ private $handler;
/** @var int @visibility protected(set) */ public $size;
function __construct() {
$this->handler = tmpfile();
}
/**
* @param string
* @return void
*/
function write($contents) {
$this->size += strlen($contents);
fwrite($this->handler, $contents);
}
/** @return void */
function send() {
fseek($this->handler, 0);
fpassthru($this->handler);

View File

@@ -6,6 +6,10 @@ namespace Adminer;
* @link http://www.coolcode.cn/?action=show&id=128
*/
/**
* @param int
* @return int
*/
function int32($n) {
while ($n >= 2147483648) {
$n -= 4294967296;
@@ -16,6 +20,11 @@ function int32($n) {
return (int) $n;
}
/**
* @param int[]
* @param bool
* @return string
*/
function long2str($v, $w) {
$s = '';
foreach ($v as $val) {
@@ -27,6 +36,11 @@ function long2str($v, $w) {
return $s;
}
/**
* @param string
* @param bool
* @return int[]
*/
function str2long($s, $w) {
$v = array_values(unpack('V*', str_pad($s, 4 * ceil(strlen($s) / 4), "\0")));
if ($w) {
@@ -35,6 +49,13 @@ function str2long($s, $w) {
return $v;
}
/**
* @param int
* @param int
* @param int
* @param int
* @return int
*/
function xxtea_mx($z, $y, $sum, $k) {
return int32((($z >> 5 & 0x7FFFFFF) ^ $y << 2) + (($y >> 3 & 0x1FFFFFFF) ^ $z << 4)) ^ int32(($sum ^ $y) + ($k ^ $z));
}

View File

@@ -219,7 +219,7 @@ function minify_js($file) {
return lzw_compress($file);
}
function compile_file($match, $callback = '') { // $callback only to match signature
function compile_file($match, $callback) { // $callback only to match signature
global $project;
$file = "";
list(, $filenames, $callback) = $match;

View File

@@ -1,9 +1,10 @@
parameters:
level: 5
level: 6
ignoreErrors:
# need to fix
- "~^Function Adminer\\\\fields_from_edit\\(\\) should return~" # Mongo and SimpleDB
- "~^Function Adminer\\\\explain\\(\\) should return Adminer\\\\Result~" # mysqli_result
- "~Adminer\\\\Result.*mysqli_result~" # mysqli_result
- "~expects array~" # different shape of array
# not real problems
@@ -20,6 +21,7 @@ parameters:
- "~expects bool~" # truthy values
- "~fread expects int<1, max>, 100000~" # 1e6
- "~'strlen' given~" # used as a bool callback
- "~Adminer\\\\(Db|PdoDb).* type specified~" # duplicate methods
# it probably doesn't like $ar[$key] instead of isset($ar[$key]) and thinks that $ar[$key] is always set
- identifier: identical.alwaysFalse
@@ -40,6 +42,7 @@ parameters:
paths:
- adminer/
scanFiles:
- compile.php # compile_file()
excludePaths:
- adminer/designs.php
@@ -53,7 +56,7 @@ parameters:
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, collation:string, privileges:int[], comment:string, primary:bool, generated:string, orig?:string, on_update:?string, on_delete?:string, inout?:string}"
@@ -61,5 +64,5 @@ parameters:
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}"
RoutineField: "array{field:string, type:string, length:?string, unsigned:string, null:bool, full_type:string, inout:string, collation:string}"
Routine: "array{name?:string, fields:list<RoutineField>, comment:string, returns?:array, definition:string, language?:string}"
Routine: "array{name?:string, fields:list<RoutineField>, comment:string, returns?:array{type:string, length:string, unsigned:string, collation:string}, definition:string, language?:string}"
BackwardKey: "array{name:string, keys:string[][]}"