mirror of
https://github.com/vrana/adminer.git
synced 2025-08-06 14:46:36 +02:00
PHPStan: Fix types
This commit is contained in:
@@ -27,8 +27,8 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
($server . $username != "" ? $username : ini_get("mysqli.default_user")),
|
($server . $username != "" ? $username : ini_get("mysqli.default_user")),
|
||||||
($server . $username . $password != "" ? $password : ini_get("mysqli.default_pw")),
|
($server . $username . $password != "" ? $password : ini_get("mysqli.default_pw")),
|
||||||
null,
|
null,
|
||||||
(is_numeric($port) ? $port : ini_get("mysqli.default_port")),
|
(is_numeric($port) ? intval($port) : ini_get("mysqli.default_port")),
|
||||||
(is_numeric($port) ? intval($port) : null),
|
(is_numeric($port) ? $port : null),
|
||||||
($ssl ? ($ssl['verify'] !== false ? 2048 : 64) : 0) // 2048 - MYSQLI_CLIENT_SSL, 64 - MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT (not available before PHP 5.6.16)
|
($ssl ? ($ssl['verify'] !== false ? 2048 : 64) : 0) // 2048 - MYSQLI_CLIENT_SSL, 64 - MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT (not available before PHP 5.6.16)
|
||||||
);
|
);
|
||||||
$this->options(MYSQLI_OPT_LOCAL_INFILE, false);
|
$this->options(MYSQLI_OPT_LOCAL_INFILE, false);
|
||||||
|
@@ -3,7 +3,10 @@ namespace Adminer;
|
|||||||
|
|
||||||
$TABLE = $_GET["edit"];
|
$TABLE = $_GET["edit"];
|
||||||
$fields = fields($TABLE);
|
$fields = fields($TABLE);
|
||||||
$where = (isset($_GET["select"]) ? ($_POST["check"] && count($_POST["check"]) == 1 ? where_check($_POST["check"][0], $fields) : "") : where($_GET, $fields));
|
$where = (isset($_GET["select"])
|
||||||
|
? ($_POST["check"] && count($_POST["check"]) == 1 ? where_check($_POST["check"][0], $fields) : "")
|
||||||
|
: where($_GET, $fields)
|
||||||
|
);
|
||||||
$update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
|
$update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
|
||||||
foreach ($fields as $name => $field) {
|
foreach ($fields as $name => $field) {
|
||||||
if (!isset($field["privileges"][$update ? "update" : "insert"]) || adminer()->fieldName($field) == "" || $field["generated"]) {
|
if (!isset($field["privileges"][$update ? "update" : "insert"]) || adminer()->fieldName($field) == "" || $field["generated"]) {
|
||||||
@@ -27,7 +30,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
|
|||||||
queries_redirect(
|
queries_redirect(
|
||||||
$location,
|
$location,
|
||||||
lang('Item has been deleted.'),
|
lang('Item has been deleted.'),
|
||||||
driver()->delete($TABLE, $query_where, !$unique_array)
|
driver()->delete($TABLE, $query_where, $unique_array ? 0 : 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -46,7 +49,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
|
|||||||
queries_redirect(
|
queries_redirect(
|
||||||
$location,
|
$location,
|
||||||
lang('Item has been updated.'),
|
lang('Item has been updated.'),
|
||||||
driver()->update($TABLE, $set, $query_where, !$unique_array)
|
driver()->update($TABLE, $set, $query_where, $unique_array ? 0 : 1)
|
||||||
);
|
);
|
||||||
if (is_ajax()) {
|
if (is_ajax()) {
|
||||||
page_headers();
|
page_headers();
|
||||||
@@ -94,7 +97,7 @@ if ($_POST["save"]) {
|
|||||||
|
|
||||||
if (!support("table") && !$fields) { // used by Mongo and SimpleDB
|
if (!support("table") && !$fields) { // used by Mongo and SimpleDB
|
||||||
if (!$where) { // insert
|
if (!$where) { // insert
|
||||||
$result = driver()->select($TABLE, array("*"), $where, array("*"));
|
$result = driver()->select($TABLE, array("*"), array(), array("*"));
|
||||||
$row = ($result ? $result->fetch_assoc() : false);
|
$row = ($result ? $result->fetch_assoc() : false);
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
$row = array(driver()->primary => "");
|
$row = array(driver()->primary => "");
|
||||||
|
@@ -159,7 +159,7 @@ class Adminer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Field caption used in select and edit
|
/** Field caption used in select and edit
|
||||||
* @param Field $field
|
* @param Field|RoutineField $field
|
||||||
* @param int $order order of column in select
|
* @param int $order order of column in select
|
||||||
* @return string HTML code, "" to ignore field
|
* @return string HTML code, "" to ignore field
|
||||||
*/
|
*/
|
||||||
@@ -259,7 +259,7 @@ class Adminer {
|
|||||||
|
|
||||||
/** Get descriptions of selected data
|
/** Get descriptions of selected data
|
||||||
* @param list<string[]> $rows all data to print
|
* @param list<string[]> $rows all data to print
|
||||||
* @param ForeignKey[] $foreignKeys
|
* @param list<ForeignKey>[] $foreignKeys
|
||||||
* @return list<string[]>
|
* @return list<string[]>
|
||||||
*/
|
*/
|
||||||
function rowDescriptions(array $rows, array $foreignKeys): array {
|
function rowDescriptions(array $rows, array $foreignKeys): array {
|
||||||
@@ -428,10 +428,8 @@ class Adminer {
|
|||||||
echo "</div></fieldset>\n";
|
echo "</div></fieldset>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Print limit box in select
|
/** Print limit box in select */
|
||||||
* @param string $limit result of selectLimitProcess()
|
function selectLimitPrint(int $limit): void {
|
||||||
*/
|
|
||||||
function selectLimitPrint(string $limit): void {
|
|
||||||
echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
|
echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
|
||||||
echo "<input type='number' name='limit' class='size' value='" . h($limit) . "'>";
|
echo "<input type='number' name='limit' class='size' value='" . h($limit) . "'>";
|
||||||
echo script("qsl('input').oninput = selectFieldChange;", "");
|
echo script("qsl('input').oninput = selectFieldChange;", "");
|
||||||
@@ -585,11 +583,9 @@ class Adminer {
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Process limit box in select
|
/** Process limit box in select */
|
||||||
* @return string expression to use in LIMIT, will be escaped
|
function selectLimitProcess(): int {
|
||||||
*/
|
return (isset($_GET["limit"]) ? intval($_GET["limit"]) : 50);
|
||||||
function selectLimitProcess(): string {
|
|
||||||
return (isset($_GET["limit"]) ? $_GET["limit"] : "50");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Process length box in select
|
/** Process length box in select
|
||||||
@@ -601,7 +597,7 @@ class Adminer {
|
|||||||
|
|
||||||
/** Process extras in select form
|
/** Process extras in select form
|
||||||
* @param string[] $where AND conditions
|
* @param string[] $where AND conditions
|
||||||
* @param ForeignKey[] $foreignKeys
|
* @param list<ForeignKey>[] $foreignKeys
|
||||||
* @return bool true if processed, false to process other parts of form
|
* @return bool true if processed, false to process other parts of form
|
||||||
*/
|
*/
|
||||||
function selectEmailProcess(array $where, array $foreignKeys): bool {
|
function selectEmailProcess(array $where, array $foreignKeys): bool {
|
||||||
@@ -657,8 +653,8 @@ class Adminer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Functions displayed in edit form
|
/** Functions displayed in edit form
|
||||||
* @param Field $field
|
* @param Field|array{null:bool} $field
|
||||||
* @return list<string>
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
function editFunctions(array $field): array {
|
function editFunctions(array $field): array {
|
||||||
$return = ($field["null"] ? "NULL/" : "");
|
$return = ($field["null"] ? "NULL/" : "");
|
||||||
@@ -1015,7 +1011,7 @@ class Adminer {
|
|||||||
}
|
}
|
||||||
echo "</script>\n";
|
echo "</script>\n";
|
||||||
}
|
}
|
||||||
echo script("syntaxHighlighting('" . (is_object(connection()) ? preg_replace('~^(\d\.?\d).*~s', '\1', connection()->server_info) : "") . "'"
|
echo script("syntaxHighlighting('" . preg_replace('~^(\d\.?\d).*~s', '\1', connection()->server_info) . "'"
|
||||||
. (connection()->flavor == 'maria' ? ", 'maria'" : (connection()->flavor == 'cockroach' ? ", 'cockroach'" : "")) . ");"
|
. (connection()->flavor == 'maria' ? ", 'maria'" : (connection()->flavor == 'cockroach' ? ", 'cockroach'" : "")) . ");"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ namespace Adminer;
|
|||||||
* @param int|numeric-string $limit
|
* @param int|numeric-string $limit
|
||||||
* @return string[] $orgtables
|
* @return string[] $orgtables
|
||||||
*/
|
*/
|
||||||
function print_select_result($result, $connection2 = null, array $orgtables = array(), $limit = 0): array {
|
function print_select_result($result, Db $connection2 = null, array $orgtables = array(), $limit = 0): array {
|
||||||
$links = array(); // colno => orgtable - create links from these columns
|
$links = array(); // colno => orgtable - create links from these columns
|
||||||
$indexes = array(); // orgtable => array(column => colno) - primary keys
|
$indexes = array(); // orgtable => array(column => colno) - primary keys
|
||||||
$columns = array(); // orgtable => array(column => ) - not selected columns in primary key
|
$columns = array(); // orgtable => array(column => ) - not selected columns in primary key
|
||||||
|
@@ -180,7 +180,7 @@ if ($_POST && !$error) {
|
|||||||
$TABLE,
|
$TABLE,
|
||||||
$set,
|
$set,
|
||||||
" WHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($unique_idf, $fields),
|
" WHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($unique_idf, $fields),
|
||||||
!$is_group && !$primary,
|
($is_group || $primary ? 0 : 1),
|
||||||
" "
|
" "
|
||||||
);
|
);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
@@ -273,7 +273,7 @@ if (!$columns && support("table")) {
|
|||||||
$page = $_GET["page"];
|
$page = $_GET["page"];
|
||||||
if ($page == "last") {
|
if ($page == "last") {
|
||||||
$found_rows = get_val(count_rows($TABLE, $where, $is_group, $group));
|
$found_rows = get_val(count_rows($TABLE, $where, $is_group, $group));
|
||||||
$page = floor(max(0, intval($found_rows) - 1) / $limit);
|
$page = floor(max(0, intval($found_rows) - 1) / intval($limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
$select2 = $select;
|
$select2 = $select;
|
||||||
@@ -492,7 +492,7 @@ if (!$columns && support("table")) {
|
|||||||
$found_rows = ($page ? $page * $limit : 0) + count($rows);
|
$found_rows = ($page ? $page * $limit : 0) + count($rows);
|
||||||
} elseif (JUSH != "sql" || !$is_group) {
|
} elseif (JUSH != "sql" || !$is_group) {
|
||||||
$found_rows = ($is_group ? false : found_rows($table_status, $where));
|
$found_rows = ($is_group ? false : found_rows($table_status, $where));
|
||||||
if ($found_rows < max(1e4, 2 * ($page + 1) * $limit)) {
|
if (intval($found_rows) < max(1e4, 2 * ($page + 1) * intval($limit))) {
|
||||||
// slow with big tables
|
// slow with big tables
|
||||||
$found_rows = first(slow_query(count_rows($TABLE, $where, $is_group, $group)));
|
$found_rows = first(slow_query(count_rows($TABLE, $where, $is_group, $group)));
|
||||||
} else {
|
} else {
|
||||||
@@ -505,7 +505,7 @@ if (!$columns && support("table")) {
|
|||||||
if ($pagination) {
|
if ($pagination) {
|
||||||
echo (($found_rows === false ? count($rows) + 1 : $found_rows - $page * $limit) > $limit
|
echo (($found_rows === false ? count($rows) + 1 : $found_rows - $page * $limit) > $limit
|
||||||
? '<p><a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" class="loadmore">' . lang('Load more data') . '</a>'
|
? '<p><a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" class="loadmore">' . lang('Load more data') . '</a>'
|
||||||
. script("qsl('a').onclick = partial(selectLoadMore, " . (+$limit) . ", '" . lang('Loading') . "…');", "")
|
. script("qsl('a').onclick = partial(selectLoadMore, " . intval($limit) . ", '" . lang('Loading') . "…');", "")
|
||||||
: ''
|
: ''
|
||||||
);
|
);
|
||||||
echo "\n";
|
echo "\n";
|
||||||
@@ -516,7 +516,7 @@ if (!$columns && support("table")) {
|
|||||||
// display first, previous 4, next 4 and last page
|
// display first, previous 4, next 4 and last page
|
||||||
$max_page = ($found_rows === false
|
$max_page = ($found_rows === false
|
||||||
? $page + (count($rows) >= $limit ? 2 : 1)
|
? $page + (count($rows) >= $limit ? 2 : 1)
|
||||||
: floor(($found_rows - 1) / $limit)
|
: floor(($found_rows - 1) / intval($limit))
|
||||||
);
|
);
|
||||||
echo "<fieldset>";
|
echo "<fieldset>";
|
||||||
if (JUSH != "simpledb") {
|
if (JUSH != "simpledb") {
|
||||||
|
@@ -310,7 +310,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
|||||||
|
|
||||||
function selectLimitPrint($limit) {
|
function selectLimitPrint($limit) {
|
||||||
echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
|
echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
|
||||||
echo html_select("limit", array("", "50", "100"), $limit);
|
echo html_select("limit", array("", 50, 100), $limit);
|
||||||
echo "</div></fieldset>\n";
|
echo "</div></fieldset>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,7 +414,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
|||||||
}
|
}
|
||||||
|
|
||||||
function selectLimitProcess() {
|
function selectLimitProcess() {
|
||||||
return (isset($_GET["limit"]) ? $_GET["limit"] : "50");
|
return (isset($_GET["limit"]) ? intval($_GET["limit"]) : 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectLengthProcess() {
|
function selectLengthProcess() {
|
||||||
|
12
phpstan.neon
12
phpstan.neon
@@ -4,8 +4,9 @@ parameters:
|
|||||||
|
|
||||||
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|Adminer\\\\Driver::\\$primary~" # Mongo and SimpleDB
|
||||||
- "~Adminer\\\\Result.*mysqli_result~" # mysqli_result
|
- "~Adminer\\\\Result.*mysqli_result~" # mysqli_result
|
||||||
|
- "~Function Adminer\\\\queries\\(\\) never returns Adminer\\\\Result~" # mysqli_result
|
||||||
|
|
||||||
# not real problems
|
# not real problems
|
||||||
- identifier: include.fileNotFound # includes in include/ relative from index.php
|
- identifier: include.fileNotFound # includes in include/ relative from index.php
|
||||||
@@ -14,6 +15,9 @@ parameters:
|
|||||||
- "~an unknown class OCI-?Lob~" # this looks like PHPStan bug
|
- "~an unknown class OCI-?Lob~" # this looks like PHPStan bug
|
||||||
- "~^Variable \\$error might not be defined~" # declared in bootstrap.inc.php
|
- "~^Variable \\$error might not be defined~" # declared in bootstrap.inc.php
|
||||||
- "~^Constant LANG not found~" # defined in lang.inc.php
|
- "~^Constant LANG not found~" # defined in lang.inc.php
|
||||||
|
- "~ an undefined \\w+ Adminer\\\\Db::~" # defined in that versions of Db
|
||||||
|
- "~^Call to an undefined method Adminer\\\\Result::seek~" # defined in MS SQL
|
||||||
|
- "~^Call to an undefined method Adminer\\\\Driver::setUserTypes~" # defined in PostgreSQL
|
||||||
- "~expects int, float given~" # this will work
|
- "~expects int, float given~" # this will work
|
||||||
- "~expects bool~" # truthy values
|
- "~expects bool~" # truthy values
|
||||||
- "~fread expects int<1, max>, 100000~" # 1e6
|
- "~fread expects int<1, max>, 100000~" # 1e6
|
||||||
@@ -25,14 +29,11 @@ parameters:
|
|||||||
- adminer/include/pdo.inc.php
|
- adminer/include/pdo.inc.php
|
||||||
- adminer/drivers/*
|
- adminer/drivers/*
|
||||||
|
|
||||||
-
|
|
||||||
message: "~ to an undefined ~" # PostgreSQL has this in its version of Db
|
|
||||||
path: adminer/drivers/pgsql.inc.php
|
|
||||||
|
|
||||||
# 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
|
||||||
- identifier: identical.alwaysFalse
|
- identifier: identical.alwaysFalse
|
||||||
- identifier: notEqual.alwaysFalse
|
- identifier: notEqual.alwaysFalse
|
||||||
- identifier: notIdentical.alwaysTrue
|
- identifier: notIdentical.alwaysTrue
|
||||||
|
- identifier: booleanNot.alwaysTrue
|
||||||
- identifier: booleanNot.alwaysFalse
|
- identifier: booleanNot.alwaysFalse
|
||||||
- identifier: booleanAnd.alwaysFalse
|
- identifier: booleanAnd.alwaysFalse
|
||||||
- identifier: booleanAnd.leftAlwaysTrue
|
- identifier: booleanAnd.leftAlwaysTrue
|
||||||
@@ -51,7 +52,6 @@ parameters:
|
|||||||
- compile.php # compile_file()
|
- compile.php # compile_file()
|
||||||
excludePaths:
|
excludePaths:
|
||||||
- adminer/adminer-plugins*
|
- adminer/adminer-plugins*
|
||||||
- adminer/lang/
|
|
||||||
- adminer/designs.php
|
- adminer/designs.php
|
||||||
- adminer/elastic.php
|
- adminer/elastic.php
|
||||||
- adminer/sqlite.php
|
- adminer/sqlite.php
|
||||||
|
Reference in New Issue
Block a user