<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(
} 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
/** 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
/** Send query with more resultsets
* @param string
- * @return bool
+ * @return Result|bool
*/
function multi_query($query) {
return $this->result = $this->query($query);
}
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
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);
// 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
}
/** Print HTML code just before the Execute button in SQL command
+ * @return void
*/
function sqlPrintAfter() {
}
/** Print before edit form
* @param string
- * @param array[]
+ * @param Field[]
* @param mixed
* @param bool
* @return void
/** Set up syntax highlight for code and <textarea>
* @param TableStatus[] result of table_status('', true)
+ * @return void
*/
function syntaxHighlighting($tables) {
global $connection;
}
}
+/** @return void */
function add_invalid_login() {
global $adminer;
$base = get_temp_dir() . "/adminer.invalid";
file_write_unlock($fp, serialize($invalids));
}
+/** @return void */
function check_invalid_login() {
global $adminer;
$invalids = array();
}
}
+/** @return void */
function unset_permanent() {
global $permanent;
foreach ($permanent as $key => $val) {
// 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));
}
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
/** 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
}
class Queries {
- static $queries = array();
- static $start;
+ /** @var string[] */ static $queries = array();
+ /** @var float */ static $start;
}
/** Execute and remember query
/** Write and unlock a file
* @param resource
* @param string
+* @return void
*/
function file_write_unlock($fp, $data) {
rewind($fp);
/** Unlock and close a file
* @param resource
+* @return void
*/
function file_unlock($fp) {
flock($fp, LOCK_UN);
}
/** 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
}
// used in compiled version
+/**
+* @param string
+* @return string
+*/
function lzw_decompress($binary) {
// convert binary string to codes
$dictionary_count = 256;
}
/** Print hidden fields
-* @param array
+* @param mixed[]
* @param list<string>
* @param string
* @return bool
return vsprintf($format, $args);
}
+/** @return void */
function switch_lang() {
global $LANG, $langs;
echo "<form action='' method='post'>\n<div id='lang'>";
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/
$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) {
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) {
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);
* @link http://www.coolcode.cn/?action=show&id=128
*/
+/**
+* @param int
+* @return int
+*/
function int32($n) {
while ($n >= 2147483648) {
$n -= 4294967296;
return (int) $n;
}
+/**
+* @param int[]
+* @param bool
+* @return string
+*/
function long2str($v, $w) {
$s = '';
foreach ($v as $val) {
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) {
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));
}
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;
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
- "~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
- identifier: while.alwaysTrue
- identifier: isset.offset
- identifier: deadCode.unreachable
-
+
paths:
- adminer/
+ scanFiles:
- compile.php # compile_file()
excludePaths:
- adminer/designs.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, collation:string, privileges:int[], comment:string, primary:bool, generated:string, orig?:string, on_update:?string, on_delete?:string, inout?: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}"
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[][]}"