]> git.joonet.de Git - adminer.git/commitdiff
PHPStan: Fix types
authorJakub Vrana <jakub@vrana.cz>
Sun, 30 Mar 2025 19:08:06 +0000 (21:08 +0200)
committerJakub Vrana <jakub@vrana.cz>
Mon, 31 Mar 2025 08:09:30 +0000 (10:09 +0200)
adminer/drivers/mysql.inc.php
adminer/edit.inc.php
adminer/include/adminer.inc.php
adminer/include/editing.inc.php
adminer/select.inc.php
editor/include/adminer.inc.php
phpstan.neon

index 260d8ea3adbf2080dae41d2d09915c241c4e63ad..1235bcc281feafc3d3afb9e6d5131bd0a30bea6d 100644 (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);
index 68925ed3076b51b2c9a0ad8ba879c04da845040e..5e661f3eefa723ddab58b66f6996efec67ca89b8 100644 (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 => "");
index 7878f5ef189741d6893a14c88b61b45d95b1cee3..f64b8710cc1d2346498b13caebc7319ffdec4de1 100644 (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'" : "")) . ");"
                );
        }
index 026e556146c2bb3daaeb9bdcea121a7cf6697299..36c5af158fc6817ce716484e8b1bc99249f1d08e 100644 (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
index 0a11ddf9f8662791154aeff023301d8c98fb3858..682fd09f5b3e903d0812672994de869d2542fe68 100644 (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") {
index 0373809ba6173065d74ac4826d885ea6f692b2e1..11df014e028f0351944fe56fb196d207ce8ab943 100644 (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() {
index c50e9f6779bfab0719c705ff84a720da5f323297..f07f05367040706631785ddc68d6b6d4f6d07524 100644 (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