mirror of
https://github.com/vrana/adminer.git
synced 2025-08-05 14:17:26 +02:00
PHPStan: Fix level 2 errors
This commit is contained in:
@@ -385,7 +385,7 @@ WHERE c.object_id = " . q($table_id)) as $row
|
||||
) {
|
||||
$type = $row["type"];
|
||||
$length = (preg_match("~char|binary~", $type)
|
||||
? $row["max_length"] / ($type[0] == 'n' ? 2 : 1)
|
||||
? intval($row["max_length"]) / ($type[0] == 'n' ? 2 : 1)
|
||||
: ($type == "decimal" ? "$row[precision],$row[scale]" : "")
|
||||
);
|
||||
$return[$row["name"]] = array(
|
||||
|
@@ -550,7 +550,6 @@ if (!defined('Adminer\DRIVER')) {
|
||||
* @param string
|
||||
* @param bool return only "Name", "Engine" and "Comment" fields
|
||||
* @return TableStatus[]
|
||||
* @phpstan-type 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}
|
||||
*/
|
||||
function table_status($name = "", $fast = false) {
|
||||
$return = array();
|
||||
@@ -596,7 +595,6 @@ if (!defined('Adminer\DRIVER')) {
|
||||
/** Get information about fields
|
||||
* @param string
|
||||
* @return Field[]
|
||||
* @phpstan-type 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}
|
||||
*/
|
||||
function fields($table) {
|
||||
global $connection;
|
||||
@@ -653,7 +651,6 @@ if (!defined('Adminer\DRIVER')) {
|
||||
* @param string
|
||||
* @param string Db to use
|
||||
* @return Index[]
|
||||
* @phpstan-type Index array{type:string, columns:list<string>, lengths:list<int>, descs:list<bool>}
|
||||
*/
|
||||
function indexes($table, $connection2 = null) {
|
||||
$return = array();
|
||||
@@ -670,7 +667,6 @@ if (!defined('Adminer\DRIVER')) {
|
||||
/** Get foreign keys in table
|
||||
* @param string
|
||||
* @return ForeignKey[]
|
||||
* @phpstan-type ForeignKey array{db:string, ns:string, table:string, source:list<string>, target:list<string>, on_delete:string, on_update:string}
|
||||
*/
|
||||
function foreign_keys($table) {
|
||||
global $driver;
|
||||
@@ -963,7 +959,6 @@ if (!defined('Adminer\DRIVER')) {
|
||||
* @param string trigger name
|
||||
* @param string
|
||||
* @return Trigger
|
||||
* @phpstan-type Trigger array{Trigger:string, Timing:string, Event:string, Of:string, Type:string, Statement:string}
|
||||
*/
|
||||
function trigger($name, $table) {
|
||||
if ($name == "") {
|
||||
@@ -1000,7 +995,6 @@ if (!defined('Adminer\DRIVER')) {
|
||||
* @param string
|
||||
* @param string "FUNCTION" or "PROCEDURE"
|
||||
* @return Routine
|
||||
* @phpstan-type 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}
|
||||
*/
|
||||
function routine($name, $type) {
|
||||
global $driver;
|
||||
@@ -1185,7 +1179,7 @@ if (!defined('Adminer\DRIVER')) {
|
||||
|
||||
/** Convert field in select and edit
|
||||
* @param Field one element from fields()
|
||||
* @return ?string
|
||||
* @return string|void
|
||||
*/
|
||||
function convert_field($field) {
|
||||
if (preg_match("~binary~", $field["type"])) {
|
||||
|
@@ -89,7 +89,7 @@ if (isset($_GET["oracle"])) {
|
||||
|
||||
private function convert($row) {
|
||||
foreach ((array) $row as $key => $val) {
|
||||
if (is_a($val, 'OCI-Lob')) {
|
||||
if (is_a($val, 'OCILob') || is_a($val, 'OCI-Lob')) {
|
||||
$row[$key] = $val->load();
|
||||
}
|
||||
}
|
||||
|
@@ -499,7 +499,7 @@ ORDER BY indisprimary DESC, indisunique DESC", $connection2) as $row
|
||||
$return[$relname]["columns"][] = $columns[$indkey];
|
||||
}
|
||||
foreach (explode(" ", $row["indoption"]) as $indoption) {
|
||||
$return[$relname]["descs"][] = ($indoption & 1 ? '1' : null); // 1 - INDOPTION_DESC
|
||||
$return[$relname]["descs"][] = (intval($indoption) & 1 ? '1' : null); // 1 - INDOPTION_DESC
|
||||
}
|
||||
}
|
||||
$return[$relname]["lengths"] = array();
|
||||
|
@@ -5,7 +5,7 @@ namespace Adminer;
|
||||
|
||||
class Adminer {
|
||||
public $operators; ///< @var list<string> operators used in select, null for all operators
|
||||
public $error = ''; ///< @var protected(set) string HTML
|
||||
public $error = ''; ///< @var string @visibility protected(set) string HTML
|
||||
|
||||
/** Name in title and navigation
|
||||
* @return string HTML code
|
||||
@@ -22,7 +22,7 @@ class Adminer {
|
||||
}
|
||||
|
||||
/** Get SSL connection options
|
||||
* @return ?string[]
|
||||
* @return string[]|void
|
||||
*/
|
||||
function connectSsl() {
|
||||
}
|
||||
@@ -221,7 +221,6 @@ class Adminer {
|
||||
* @param string
|
||||
* @param string
|
||||
* @return BackwardKey[]
|
||||
* @phpstan-type BackwardKey array{name:string, keys:string[][]}
|
||||
*/
|
||||
function backwardKeys($table, $tableName) {
|
||||
return array();
|
||||
@@ -289,7 +288,7 @@ class Adminer {
|
||||
/** Get a link to use in select table
|
||||
* @param string raw value of the field
|
||||
* @param Field single field returned from fields()
|
||||
* @return ?string null to create the default link
|
||||
* @return string|void null to create the default link
|
||||
*/
|
||||
function selectLink($val, $field) {
|
||||
}
|
||||
|
@@ -61,14 +61,14 @@ abstract class SqlDriver {
|
||||
|
||||
/** Get enum values
|
||||
* @param Field
|
||||
* @return ?string
|
||||
* @return string|void
|
||||
*/
|
||||
function enumLength($field) {
|
||||
}
|
||||
|
||||
/** Function used to convert the value inputted by user
|
||||
* @param Field
|
||||
* @return ?string
|
||||
* @return string|void
|
||||
*/
|
||||
function unconvertFunction($field) {
|
||||
}
|
||||
@@ -187,7 +187,7 @@ abstract class SqlDriver {
|
||||
/** Return query with a timeout
|
||||
* @param string
|
||||
* @param int seconds
|
||||
* @return ?string null if the driver doesn't support query timeouts
|
||||
* @return string|void null if the driver doesn't support query timeouts
|
||||
*/
|
||||
function slowQuery($query, $timeout) {
|
||||
}
|
||||
@@ -231,7 +231,7 @@ abstract class SqlDriver {
|
||||
}
|
||||
|
||||
/** Get warnings about the last command
|
||||
* @return ?string HTML
|
||||
* @return string|void HTML
|
||||
*/
|
||||
function warnings() {
|
||||
}
|
||||
@@ -239,7 +239,7 @@ abstract class SqlDriver {
|
||||
/** Get help link for table
|
||||
* @param string
|
||||
* @param bool
|
||||
* @return ?string relative URL
|
||||
* @return string|void relative URL
|
||||
*/
|
||||
function tableHelp($name, $is_view = false) {
|
||||
}
|
||||
|
@@ -299,7 +299,7 @@ function default_value($field) {
|
||||
|
||||
/** Get type class to use in CSS
|
||||
* @param string
|
||||
* @return ?string class=''
|
||||
* @return string|void class=''
|
||||
*/
|
||||
function type_class($type) {
|
||||
foreach (
|
||||
|
@@ -274,7 +274,7 @@ function get_rows($query, $connection2 = null, $error = "<p class='error'>") {
|
||||
/** Find unique identifier of a row
|
||||
* @param string[]
|
||||
* @param Index[] result of indexes()
|
||||
* @return ?string[] null if there is no unique identifier
|
||||
* @return string[]|void null if there is no unique identifier
|
||||
*/
|
||||
function unique_array($row, $indexes) {
|
||||
foreach ($indexes as $index) {
|
||||
|
@@ -343,7 +343,7 @@ function input($field, $value, $function, $autofocus = false) {
|
||||
}
|
||||
|
||||
/** Process edit input field
|
||||
* @param one field from fields()
|
||||
* @param Field one field from fields()
|
||||
* @return string or false to leave the original value
|
||||
*/
|
||||
function process_input($field) {
|
||||
@@ -417,7 +417,7 @@ function search_tables() {
|
||||
|
||||
/** Return events to display help on mouse over
|
||||
* @param string JS expression
|
||||
* @param bool JS expression
|
||||
* @param int JS expression
|
||||
* @return string
|
||||
*/
|
||||
function on_help($command, $side = 0) {
|
||||
|
@@ -2,7 +2,7 @@
|
||||
namespace Adminer;
|
||||
|
||||
class Plugins extends Adminer {
|
||||
public $plugins; ///< @var protected(set) array
|
||||
public $plugins; ///< @var list<object> @visibility protected(set)
|
||||
|
||||
/** Register plugins
|
||||
* @param list<object> object instances or null to autoload plugins from adminer-plugins/
|
||||
|
@@ -2,7 +2,8 @@
|
||||
namespace Adminer;
|
||||
|
||||
class TmpFile {
|
||||
private $handler, $size;
|
||||
private $handler;
|
||||
public $size; ///< @visibility protected(set)
|
||||
|
||||
function __construct() {
|
||||
$this->handler = tmpfile();
|
||||
|
@@ -3,6 +3,7 @@ namespace Adminer;
|
||||
|
||||
page_header(lang('Database schema'), "", array(), h(DB . ($_GET["ns"] ? ".$_GET[ns]" : "")));
|
||||
|
||||
/** @var array{float, float}[] */
|
||||
$table_pos = array();
|
||||
$table_pos_js = array();
|
||||
$SCHEMA = ($_GET["schema"] ?: $_COOKIE["adminer_schema-" . str_replace(".", "_", DB)]); // $_COOKIE["adminer_schema"] was used before 3.2.0 //! ':' in table name
|
||||
@@ -14,6 +15,7 @@ foreach ($matches as $i => $match) {
|
||||
|
||||
$top = 0;
|
||||
$base_left = -1;
|
||||
/** @var array{fields:Field[], pos:array{float, float}, references:string[][][]}[] */
|
||||
$schema = array(); // table => array("fields" => array(name => field), "pos" => array(top, left), "references" => array(table => array(left => array(source, target))))
|
||||
$referenced = array(); // target_table => array(table => array(left => target_column))
|
||||
$lefts = array(); // float => bool
|
||||
|
@@ -270,7 +270,7 @@ if (!$columns && support("table")) {
|
||||
$page = $_GET["page"];
|
||||
if ($page == "last") {
|
||||
$found_rows = get_val(count_rows($TABLE, $where, $is_group, $group));
|
||||
$page = floor(max(0, $found_rows - 1) / $limit);
|
||||
$page = floor(max(0, intval($found_rows) - 1) / $limit);
|
||||
}
|
||||
|
||||
$select2 = $select;
|
||||
|
@@ -15,7 +15,7 @@ function email_header($header) {
|
||||
* @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>}
|
||||
* @return bool
|
||||
*/
|
||||
function send_mail($email, $subject, $message, $from = "", $files = array()) {
|
||||
|
13
phpstan.neon
13
phpstan.neon
@@ -1,14 +1,25 @@
|
||||
parameters:
|
||||
level: 1
|
||||
level: 2
|
||||
ignoreErrors:
|
||||
- identifier: include.fileNotFound # relative includes
|
||||
- identifier: includeOnce.fileNotFound # ./adminer-plugins.php
|
||||
- "~^Function (set_magic_quotes_runtime|mysql_)~" # PHP < 7 functions
|
||||
- "~^Instantiated class Adminer\\w~" # no support for classes defined inside function
|
||||
- "~^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
|
||||
- "~OCI-?Lob~" # maybe include stub?
|
||||
- "~Adminer\\\\Db::~" # diagnose!
|
||||
paths:
|
||||
- .
|
||||
phpVersion:
|
||||
min: 70100
|
||||
max: 80499
|
||||
checkMissingCallableSignature: true
|
||||
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}"
|
||||
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}"
|
||||
Index: "array{type:string, columns:list<string>, lengths:list<int>, 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}"
|
||||
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}"
|
||||
BackwardKey: "array{name:string, keys:string[][]}"
|
||||
|
@@ -9,7 +9,7 @@ if (isset($_GET["mongo"])) {
|
||||
if (class_exists('MongoDB\Driver\Manager')) {
|
||||
class Db {
|
||||
public $extension = "MongoDB", $flavor = '', $server_info = MONGODB_VERSION, $affected_rows, $error, $last_id;
|
||||
/** @var MongoDB\Driver\Manager */
|
||||
/** @var \MongoDB\Driver\Manager */
|
||||
public $_link;
|
||||
public $_db, $_db_name;
|
||||
|
||||
|
Reference in New Issue
Block a user