]> git.joonet.de Git - adminer.git/commitdiff
PHPStan: Fix level 2 errors
authorJakub Vrana <jakub@vrana.cz>
Wed, 26 Mar 2025 14:38:04 +0000 (15:38 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 26 Mar 2025 15:22:15 +0000 (16:22 +0100)
16 files changed:
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/include/adminer.inc.php
adminer/include/driver.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php
adminer/include/html.inc.php
adminer/include/plugins.inc.php
adminer/include/tmpfile.inc.php
adminer/schema.inc.php
adminer/select.inc.php
editor/include/editing.inc.php
phpstan.neon
plugins/drivers/mongo.php

index c9302cf3baf3e56a420d5105d4f7c39e00610fb2..061547aa30ff5837f15f630f50a458f951759037 100644 (file)
@@ -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(
index 423b0a4e561d39f0d016555c38d1763434a04465..177d178b1fbaccb6913924ada42ccff1c38b39b7 100644 (file)
@@ -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"])) {
index 21edace3bf7457df8b3bd4351f00b9dd59161181..b7eff9537328620d701d99b30c948eb927dcc88a 100644 (file)
@@ -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();
                                        }
                                }
index a699126edeb81468dfa79a7627add77c3f14f061..be4293af051f1407e41cedf364244dadc221b6e1 100644 (file)
@@ -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();
index b4ccb81ac1712d5b3dfe50fba86ddf0eb616f329..869533e7fb722e6a891f8ddaae5de21cbd364e45 100644 (file)
@@ -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) {
        }
index a9af6ab021f389a8d843fa6ca62e3bf4fdfa038c..2ae93d9659f21136d6b29d6fc061a9a0320442e9 100644 (file)
@@ -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) {
        }
index ebb5f89bcd483a2ca6e0cb3966d8420930b1e8a2..78bed1de2b3e380e42b2c8b4310da4fd4bbaa510 100644 (file)
@@ -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 (
index 1d457bbc16ed5813e7a224ec0c9da37650835932..db3ca1289607653afc5d94112fec91e6003a50a4 100644 (file)
@@ -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) {
index dc0f2f72edccaa86698e2986af8875706a319693..a265a18f85c58e399d353430cf74e77962af5da7 100644 (file)
@@ -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) {
index da222c55da7be7aca991622163f038024d7ed6e5..294c6135f3c233dcb4a8b6a15709a4ce0334c76d 100644 (file)
@@ -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/
index b75f478f2718be111f59793eca521ea680358e5b..a9c87d29a9ce39fab207b35bf059a6e6a870aa60 100644 (file)
@@ -2,7 +2,8 @@
 namespace Adminer;
 
 class TmpFile {
-       private $handler, $size;
+       private $handler;
+       public $size; ///< @visibility protected(set)
 
        function __construct() {
                $this->handler = tmpfile();
index b2284d19491ed9456d111f36be64bd44dd55e3da..b3ab4e41e35f07885b74e2f98f5e6ca16c2b529e 100644 (file)
@@ -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
index d0dba9251bfdd03e5c99623fd1d995879d0e9b89..cb0db3c529f0e93a7f729d8ffe8f0178c1e26830 100644 (file)
@@ -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;
index 529a0be697cf805086cfffcfbc737afa54815434..6dacd5106b59e47f65036fd52a71df74efb86565 100644 (file)
@@ -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()) {
index df336bbd8622a6c9301d364eeaf2fbf993d23bb8..ad5a02d775d2b87aed80059c5531a3f2c9e53e95 100644 (file)
@@ -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[][]}"
index bbe925df725f2a631971482efac35fd8b3aa421e..f36f6adc4f9ba05d8009a382577845a9eaff9e97 100644 (file)
@@ -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;