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

PHPStan: Fix types

This commit is contained in:
Jakub Vrana
2025-03-30 21:08:06 +02:00
parent c05b1ac048
commit 016c1b2357
7 changed files with 34 additions and 35 deletions

View File

@@ -27,8 +27,8 @@ if (!defined('Adminer\DRIVER')) {
($server . $username != "" ? $username : ini_get("mysqli.default_user")),
($server . $username . $password != "" ? $password : ini_get("mysqli.default_pw")),
null,
(is_numeric($port) ? $port : ini_get("mysqli.default_port")),
(is_numeric($port) ? intval($port) : null),
(is_numeric($port) ? intval($port) : ini_get("mysqli.default_port")),
(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)
);
$this->options(MYSQLI_OPT_LOCAL_INFILE, false);

View File

@@ -3,7 +3,10 @@ namespace Adminer;
$TABLE = $_GET["edit"];
$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);
foreach ($fields as $name => $field) {
if (!isset($field["privileges"][$update ? "update" : "insert"]) || adminer()->fieldName($field) == "" || $field["generated"]) {
@@ -27,7 +30,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
queries_redirect(
$location,
lang('Item has been deleted.'),
driver()->delete($TABLE, $query_where, !$unique_array)
driver()->delete($TABLE, $query_where, $unique_array ? 0 : 1)
);
} else {
@@ -46,7 +49,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
queries_redirect(
$location,
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()) {
page_headers();
@@ -94,7 +97,7 @@ if ($_POST["save"]) {
if (!support("table") && !$fields) { // used by Mongo and SimpleDB
if (!$where) { // insert
$result = driver()->select($TABLE, array("*"), $where, array("*"));
$result = driver()->select($TABLE, array("*"), array(), array("*"));
$row = ($result ? $result->fetch_assoc() : false);
if (!$row) {
$row = array(driver()->primary => "");

View File

@@ -159,7 +159,7 @@ class Adminer {
}
/** Field caption used in select and edit
* @param Field $field
* @param Field|RoutineField $field
* @param int $order order of column in select
* @return string HTML code, "" to ignore field
*/
@@ -259,7 +259,7 @@ class Adminer {
/** Get descriptions of selected data
* @param list<string[]> $rows all data to print
* @param ForeignKey[] $foreignKeys
* @param list<ForeignKey>[] $foreignKeys
* @return list<string[]>
*/
function rowDescriptions(array $rows, array $foreignKeys): array {
@@ -428,10 +428,8 @@ class Adminer {
echo "</div></fieldset>\n";
}
/** Print limit box in select
* @param string $limit result of selectLimitProcess()
*/
function selectLimitPrint(string $limit): void {
/** Print limit box in select */
function selectLimitPrint(int $limit): void {
echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
echo "<input type='number' name='limit' class='size' value='" . h($limit) . "'>";
echo script("qsl('input').oninput = selectFieldChange;", "");
@@ -585,11 +583,9 @@ class Adminer {
return $return;
}
/** Process limit box in select
* @return string expression to use in LIMIT, will be escaped
*/
function selectLimitProcess(): string {
return (isset($_GET["limit"]) ? $_GET["limit"] : "50");
/** Process limit box in select */
function selectLimitProcess(): int {
return (isset($_GET["limit"]) ? intval($_GET["limit"]) : 50);
}
/** Process length box in select
@@ -601,7 +597,7 @@ class Adminer {
/** Process extras in select form
* @param string[] $where AND conditions
* @param ForeignKey[] $foreignKeys
* @param list<ForeignKey>[] $foreignKeys
* @return bool true if processed, false to process other parts of form
*/
function selectEmailProcess(array $where, array $foreignKeys): bool {
@@ -657,8 +653,8 @@ class Adminer {
}
/** Functions displayed in edit form
* @param Field $field
* @return list<string>
* @param Field|array{null:bool} $field
* @return string[]
*/
function editFunctions(array $field): array {
$return = ($field["null"] ? "NULL/" : "");
@@ -1015,7 +1011,7 @@ class Adminer {
}
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'" : "")) . ");"
);
}

View File

@@ -9,7 +9,7 @@ namespace Adminer;
* @param int|numeric-string $limit
* @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
$indexes = array(); // orgtable => array(column => colno) - primary keys
$columns = array(); // orgtable => array(column => ) - not selected columns in primary key

View File

@@ -180,7 +180,7 @@ if ($_POST && !$error) {
$TABLE,
$set,
" WHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($unique_idf, $fields),
!$is_group && !$primary,
($is_group || $primary ? 0 : 1),
" "
);
if (!$result) {
@@ -273,7 +273,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, intval($found_rows) - 1) / $limit);
$page = floor(max(0, intval($found_rows) - 1) / intval($limit));
}
$select2 = $select;
@@ -492,7 +492,7 @@ if (!$columns && support("table")) {
$found_rows = ($page ? $page * $limit : 0) + count($rows);
} elseif (JUSH != "sql" || !$is_group) {
$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
$found_rows = first(slow_query(count_rows($TABLE, $where, $is_group, $group)));
} else {
@@ -505,7 +505,7 @@ if (!$columns && support("table")) {
if ($pagination) {
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>'
. script("qsl('a').onclick = partial(selectLoadMore, " . (+$limit) . ", '" . lang('Loading') . "…');", "")
. script("qsl('a').onclick = partial(selectLoadMore, " . intval($limit) . ", '" . lang('Loading') . "…');", "")
: ''
);
echo "\n";
@@ -516,7 +516,7 @@ if (!$columns && support("table")) {
// display first, previous 4, next 4 and last page
$max_page = ($found_rows === false
? $page + (count($rows) >= $limit ? 2 : 1)
: floor(($found_rows - 1) / $limit)
: floor(($found_rows - 1) / intval($limit))
);
echo "<fieldset>";
if (JUSH != "simpledb") {

View File

@@ -310,7 +310,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
function selectLimitPrint($limit) {
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";
}
@@ -414,7 +414,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
}
function selectLimitProcess() {
return (isset($_GET["limit"]) ? $_GET["limit"] : "50");
return (isset($_GET["limit"]) ? intval($_GET["limit"]) : 50);
}
function selectLengthProcess() {

View File

@@ -4,8 +4,9 @@ parameters:
ignoreErrors:
# 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
- "~Function Adminer\\\\queries\\(\\) never returns Adminer\\\\Result~" # mysqli_result
# not real problems
- 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
- "~^Variable \\$error might not be defined~" # declared in bootstrap.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 bool~" # truthy values
- "~fread expects int<1, max>, 100000~" # 1e6
@@ -25,14 +29,11 @@ parameters:
- adminer/include/pdo.inc.php
- 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
- identifier: identical.alwaysFalse
- identifier: notEqual.alwaysFalse
- identifier: notIdentical.alwaysTrue
- identifier: booleanNot.alwaysTrue
- identifier: booleanNot.alwaysFalse
- identifier: booleanAnd.alwaysFalse
- identifier: booleanAnd.leftAlwaysTrue
@@ -51,7 +52,6 @@ parameters:
- compile.php # compile_file()
excludePaths:
- adminer/adminer-plugins*
- adminer/lang/
- adminer/designs.php
- adminer/elastic.php
- adminer/sqlite.php