]> git.joonet.de Git - adminer.git/commitdiff
PHPStan: Use int for $limit
authorJakub Vrana <jakub@vrana.cz>
Sun, 30 Mar 2025 19:08:19 +0000 (21:08 +0200)
committerJakub Vrana <jakub@vrana.cz>
Mon, 31 Mar 2025 08:09:30 +0000 (10:09 +0200)
14 files changed:
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/adminer.inc.php
adminer/include/driver.inc.php
adminer/select.inc.php
plugins/drivers/clickhouse.php
plugins/drivers/elastic.php
plugins/drivers/firebird.php
plugins/drivers/imap.php
plugins/drivers/mongo.php
plugins/drivers/simpledb.php

index 58c1141dfd69ed87b502ca0443e650bcb9737c10..8a05696c9a37d2e0f51485e87b51bef96135838f 100644 (file)
@@ -301,7 +301,7 @@ if (isset($_GET["mssql"])) {
        }
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
-               return ($limit !== null ? " TOP (" . ($limit + $offset) . ")" : "") . " $query$where"; // seek later
+               return ($limit ? " TOP (" . ($limit + $offset) . ")" : "") . " $query$where"; // seek later
        }
 
        function limit1($table, $query, $where, $separator = "\n") {
index 1235bcc281feafc3d3afb9e6d5131bd0a30bea6d..d5690ce3fad2a31c128759c3117751f1b1af8dae 100644 (file)
@@ -387,7 +387,7 @@ if (!defined('Adminer\DRIVER')) {
        * @param string $where including WHERE
        */
        function limit(string $query, string $where, int $limit, int $offset = 0, string $separator = " "): string {
-               return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
+               return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
        }
 
        /** Formulate SQL modification query with limit 1
index 88bbfb5d0cb48f2664ff6148ae3b21f28b8f847f..7ec8d4ae47eb74435578d4f6d229e51abcaae747 100644 (file)
@@ -200,7 +200,7 @@ ORDER BY 1"
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
                return ($offset ? " * FROM (SELECT t.*, rownum AS rnum FROM (SELECT $query$where) t WHERE rownum <= " . ($limit + $offset) . ") WHERE rnum > $offset"
-                       : ($limit !== null ? " * FROM (SELECT $query$where) WHERE rownum <= " . ($limit + $offset)
+                       : ($limit ? " * FROM (SELECT $query$where) WHERE rownum <= " . ($limit + $offset)
                        : " $query$where"
                ));
        }
index 958bbc78de2cb2f85a3a66d5a8caf08468084389..5c9b0f8b3f2f26f426e6a61c31fbeb45bc53b5de 100644 (file)
@@ -319,7 +319,7 @@ ORDER BY datname");
        }
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
-               return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
+               return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
        }
 
        function limit1($table, $query, $where, $separator = "\n") {
index 5a2ac2982cc6a8ef3b212d83fa4d80ee8ee8fb02..df910d1b51d109767c6881d02fad04310e3c30d7 100644 (file)
@@ -178,7 +178,7 @@ if (isset($_GET["sqlite"])) {
        }
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
-               return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
+               return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
        }
 
        function limit1($table, $query, $where, $separator = "\n") {
index f64b8710cc1d2346498b13caebc7319ffdec4de1..45c12430dd69a83f1358043af9bd46572610266f 100644 (file)
@@ -431,7 +431,7 @@ class Adminer {
        /** 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 "<input type='number' name='limit' class='size' value='" . intval($limit) . "'>";
                echo script("qsl('input').oninput = selectFieldChange;", "");
                echo "</div></fieldset>\n";
        }
@@ -613,7 +613,7 @@ class Adminer {
        * @param int $page index of page starting at zero
        * @return string empty string to use default query
        */
-       function selectQueryBuild(array $select, array $where, array $group, array $order, ?int $limit, ?int $page): string {
+       function selectQueryBuild(array $select, array $where, array $group, array $order, int $limit, ?int $page): string {
                return "";
        }
 
index cc9e10dab5376cb714a634f517c16119f389b23f..9452beaf571be92049fa0bfc7e5877537d9c7c82 100644 (file)
@@ -76,19 +76,19 @@ abstract class SqlDriver {
        * @param list<string> $where result of adminer()->selectSearchProcess()
        * @param list<string> $group result of adminer()->selectColumnsProcess()[1]
        * @param list<string> $order result of adminer()->selectOrderProcess()
-       * @param int|numeric-string $limit result of adminer()->selectLimitProcess()
+       * @param int $limit result of adminer()->selectLimitProcess()
        * @param int $page index of page starting at zero
        * @param bool $print whether to print the query
        * @return Result|false
        */
-       function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) {
+       function select(string $table, array $select, array $where, array $group, array $order = array(), int $limit = 1, ?int $page = 0, bool $print = false) {
                $is_group = (count($group) < count($select));
                $query = adminer()->selectQueryBuild($select, $where, $group, $order, $limit, $page);
                if (!$query) {
                        $query = "SELECT" . limit(
-                               ($_GET["page"] != "last" && $limit != "" && $group && $is_group && JUSH == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
+                               ($_GET["page"] != "last" && $limit && $group && $is_group && JUSH == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
                                ($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""),
-                               ($limit != "" ? +$limit : null),
+                               $limit,
                                ($page ? $limit * $page : 0),
                                "\n"
                        );
index 682fd09f5b3e903d0812672994de869d2542fe68..81e07af171fa02c88462026c67a6c358f2e1ff10 100644 (file)
@@ -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) / intval($limit));
+               $page = floor(max(0, intval($found_rows) - 1) / $limit);
        }
 
        $select2 = $select;
@@ -318,7 +318,7 @@ if (!$columns && support("table")) {
                }
 
                // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
-               if ($_GET["page"] != "last" && $limit != "" && $group && $is_group && JUSH == "sql") {
+               if ($_GET["page"] != "last" && $limit && $group && $is_group && JUSH == "sql") {
                        $found_rows = get_val(" SELECT FOUND_ROWS()"); // space to allow mysql.trace_mode
                }
 
@@ -488,11 +488,11 @@ if (!$columns && support("table")) {
                                $exact_count = true;
                                $found_rows = null;
                                if ($_GET["page"] != "last") {
-                                       if ($limit == "" || (count($rows) < $limit && ($rows || !$page))) {
+                                       if (!$limit || (count($rows) < $limit && ($rows || !$page))) {
                                                $found_rows = ($page ? $page * $limit : 0) + count($rows);
                                        } elseif (JUSH != "sql" || !$is_group) {
                                                $found_rows = ($is_group ? false : found_rows($table_status, $where));
-                                               if (intval($found_rows) < max(1e4, 2 * ($page + 1) * intval($limit))) {
+                                               if (intval($found_rows) < max(1e4, 2 * ($page + 1) * $limit)) {
                                                        // slow with big tables
                                                        $found_rows = first(slow_query(count_rows($TABLE, $where, $is_group, $group)));
                                                } else {
@@ -501,11 +501,11 @@ if (!$columns && support("table")) {
                                        }
                                }
 
-                               $pagination = ($limit != "" && ($found_rows === false || $found_rows > $limit || $page));
+                               $pagination = ($limit && ($found_rows === false || $found_rows > $limit || $page));
                                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, " . intval($limit) . ", '" . lang('Loading') . "…');", "")
+                                                       . script("qsl('a').onclick = partial(selectLoadMore, $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) / intval($limit))
+                                               : floor(($found_rows - 1) / $limit)
                                        );
                                        echo "<fieldset>";
                                        if (JUSH != "simpledb") {
index ed760560283cd6612fd95fdc0051d6e61fb0f35d..eae90dd6911a4346a1dd421dd2c445790f87cac8 100644 (file)
@@ -243,7 +243,7 @@ if (isset($_GET["clickhouse"])) {
        }
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
-               return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? ", $offset" : "") : "");
+               return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? ", $offset" : "") : "");
        }
 
        function limit1($table, $query, $where, $separator = "\n") {
index c7db74ef5544bf1b52d61084628cf7f63ad4c64e..b22af2cdd11f7e5b62a46056d9e28f594b29c85b 100644 (file)
@@ -146,7 +146,7 @@ if (isset($_GET["elastic"])) {
                        }
 
                        if ($limit) {
-                               $data["size"] = +$limit;
+                               $data["size"] = $limit;
                                if ($page) {
                                        $data["from"] = ($page * $limit);
                                }
@@ -308,7 +308,7 @@ if (isset($_GET["elastic"])) {
        }
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
-               return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
+               return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
        }
 
        function collations() {
index c4a6ca6572b656efc98d65d04d9f03f73c9951a3..d81bbd94d95ef61d78106dd4025534e16b58b2ae 100644 (file)
@@ -107,7 +107,7 @@ if (isset($_GET["firebird"])) {
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
                $return = '';
-               $return .= ($limit !== null ? $separator . "FIRST $limit" . ($offset ? " SKIP $offset" : "") : "");
+               $return .= ($limit ? $separator . "FIRST $limit" . ($offset ? " SKIP $offset" : "") : "");
                $return .= " $query$where";
                return $return;
        }
index 31b18fbfef81a7b76bce3cf8d4d4c1323fc2b2e6..29583057c6aa9b3c02f7041fb698c32e30de810a 100644 (file)
@@ -208,7 +208,7 @@ if (isset($_GET["imap"])) {
        }
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
-               return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
+               return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
        }
 
        function idf_escape($idf) {
index 5a77ed1187913273b50190e01b67d828d124f9ea..ae50ac81a0ab84366ee281e4ec9ae2128649d027 100644 (file)
@@ -344,10 +344,7 @@ if (isset($_GET["mongo"])) {
                                $val = preg_replace('~ DESC$~', '', $val, 1, $count);
                                $sort[$val] = ($count ? -1 : 1);
                        }
-                       if (isset($_GET['limit']) && is_numeric($_GET['limit']) && $_GET['limit'] > 0) {
-                               $limit = $_GET['limit'];
-                       }
-                       $limit = min(200, max(1, (int) $limit));
+                       $limit = min(200, max(1, $limit));
                        $skip = $page * $limit;
                        try {
                                return new Result($this->conn->_link->executeQuery($this->conn->_db_name . ".$table", new \MongoDB\Driver\Query($where, array('projection' => $select, 'limit' => $limit, 'skip' => $skip, 'sort' => $sort))));
index 4bcc0f1289df60d18705b1dca03d8de3f4c1e56a..52f558be8a2dd17eede19f184ea3575c1e2a4752 100644 (file)
@@ -340,7 +340,7 @@ if (isset($_GET["simpledb"])) {
        }
 
        function limit($query, $where, $limit, $offset = 0, $separator = " ") {
-               return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" : "");
+               return " $query$where" . ($limit ? $separator . "LIMIT $limit" : "");
        }
 
        function unconvert_field($field, $return) {