]> git.joonet.de Git - adminer.git/commitdiff
PHPStan: Fix level 4 errors
authorJakub Vrana <jakub@vrana.cz>
Wed, 26 Mar 2025 17:32:45 +0000 (18:32 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 26 Mar 2025 17:32:45 +0000 (18:32 +0100)
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/include/auth.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php
adminer/select.inc.php
phpstan.neon

index 0447e95397632873fc0d784bf2b40fa15aa81816..9985df17f7059569ba03ce87a00154fc124aed64 100644 (file)
@@ -444,7 +444,7 @@ if (!defined('Adminer\DRIVER')) {
 
        /** Connect to the database
        * @param array{string, string, string} [$server, $username, $password]
-       * @return mixed Db or string for error
+       * @return string|Db string for error
        */
        function connect($credentials) {
                global $drivers;
@@ -1073,47 +1073,12 @@ if (!defined('Adminer\DRIVER')) {
        /** Get approximate number of rows
        * @param TableStatus
        * @param list<string>
-       * @return numeric-string|void null if approximate number can't be retrieved
+       * @return numeric-string|null null if approximate number can't be retrieved
        */
        function found_rows($table_status, $where) {
                return ($where || $table_status["Engine"] != "InnoDB" ? null : $table_status["Rows"]);
        }
 
-       /* Not used is MySQL but checked in compile.php:
-       /** Get user defined types
-       * @return string[] [$id => $name]
-       function types() {
-               return array();
-       }
-
-       /** Get values of user defined type
-       * @param int
-       * @return string
-       function type_values($id) {
-               return "";
-       }
-
-       /** Get existing schemas
-       * @return list<string>
-       function schemas() {
-               return array();
-       }
-
-       /** Get current schema
-       * @return string
-       function get_schema() {
-               return "";
-       }
-
-       /** Set current schema
-       * @param string
-       * @param Db
-       * @return bool
-       function set_schema($schema, $connection2 = null) {
-               return true;
-       }
-       */
-
        /** Get SQL command to create table
        * @param string
        * @param bool
@@ -1241,4 +1206,44 @@ if (!defined('Adminer\DRIVER')) {
        function max_connections() {
                return get_val("SELECT @@max_connections");
        }
+
+       // Not used is MySQL but checked in compile.php:
+
+       /** Get user defined types
+       * @return string[] [$id => $name]
+       */
+       function types() {
+               return array();
+       }
+
+       /** Get values of user defined type
+       * @param int
+       * @return string
+       */
+       function type_values($id) {
+               return "";
+       }
+
+       /** Get existing schemas
+       * @return list<string>
+       */
+       function schemas() {
+               return array();
+       }
+
+       /** Get current schema
+       * @return string
+       */
+       function get_schema() {
+               return "";
+       }
+
+       /** Set current schema
+       * @param string
+       * @param Db
+       * @return bool
+       */
+       function set_schema($schema, $connection2 = null) {
+               return true;
+       }
 }
index 82e7166f15a582a9420b0a5d26285feaeb565c70..490ffdfe67080b37dcc39a67f134cb12dd07a7e0 100644 (file)
@@ -854,7 +854,7 @@ AND typelem = 0"
                }
                $fields = fields($table);
 
-               if (!$status || empty($fields)) {
+               if (count($status) < 2 || empty($fields)) {
                        return false;
                }
 
index ebf3b63fa6e489fa23f54f06248aa3b45d54f011..9a0ff67dfcfb977ee73211e5f480ee7036ee03f7 100644 (file)
@@ -61,6 +61,7 @@ function check_invalid_login() {
                        break;
                }
        }
+       /** @var array{int, int} */
        $invalid = idx($invalids, $adminer->bruteForceKey(), array());
        $next_attempt = ($invalid[1] > 29 ? $invalid[0] - time() : 0); // allow 30 invalid attempts
        if ($next_attempt > 0) { //! do the same with permanent login
index 9981b43bab5b1417a969cff992631736ddef0a66..97a492bce92c877f8c72d1160f75b4afffa42ab7 100644 (file)
@@ -124,7 +124,7 @@ function referencable_primary($self) {
 
 /** Print SQL <textarea> tag
 * @param string
-* @param string or array in which case [0] of every element is used
+* @param string|list<array{string}>
 * @param int
 * @param int
 * @return void
index 013b7b30a83b13235e5d670ad81314b66007175a..422027abf5f90bbc357a27ccdf3554d4b5a209fc 100644 (file)
@@ -174,7 +174,7 @@ function sid() {
 * @param string
 * @param string
 * @param string
-* @param string
+* @param ?string
 * @return void
 */
 function set_password($vendor, $server, $username, $password) {
@@ -185,7 +185,7 @@ function set_password($vendor, $server, $username, $password) {
 }
 
 /** Get password from session
-* @return string or null for missing password or false for expired password
+* @return string|false|null null for missing password, false for expired password
 */
 function get_password() {
        $return = get_session("pwds");
@@ -549,7 +549,7 @@ class Queries {
 
 /** Execute and remember query
 * @param string end with ';' to use DELIMITER
-* @return Result
+* @return Result|bool
 */
 function queries($query) {
        global $connection;
@@ -902,7 +902,7 @@ function rand_string() {
 }
 
 /** Format value to use in select
-* @param string
+* @param string|string[]
 * @param string
 * @param Field
 * @param int
@@ -945,7 +945,7 @@ function select_value($val, $link, $field, $text_length) {
 }
 
 /** Check whether the string is e-mail address
-* @param string
+* @param ?string
 * @return bool
 */
 function is_mail($email) {
index cb0db3c529f0e93a7f729d8ffe8f0178c1e26830..cd305aeb5f7c0ed31e77a250faf2b0e5fd7d1cfe 100644 (file)
@@ -337,6 +337,7 @@ if (!$columns && support("table")) {
                        $rank = 1;
                        foreach ($rows[0] as $key => $val) {
                                if (!isset($unselected[$key])) {
+                                       /** @var array{fun?:string, col?:string} */
                                        $val = idx($_GET["columns"], key($select)) ?: array();
                                        $field = $fields[$select ? ($val ? $val["col"] : current($select)) : $key];
                                        $name = ($field ? $adminer->fieldName($field, $rank) : ($val["fun"] ? "*" : h($key)));
index a3cd2b2c8fd66a52a042f1bed332640ff5b3b944..5902005ea543b8c6913032d24d4dc4d1751d8a52 100644 (file)
@@ -1,10 +1,10 @@
 parameters:
-       level: 3
+       level: 4
        ignoreErrors:
                # need to fix
                - "~^Function Adminer\\\\fields_from_edit\\(\\) should return~" # Mongo and SimpleDB
                - "~^Function Adminer\\\\explain\\(\\) should return Adminer\\\\Result~" # mysqli_result
-
+               
                # not real problems
                - identifier: include.fileNotFound # relative includes
                - identifier: includeOnce.fileNotFound # ./adminer-plugins.php
@@ -12,10 +12,25 @@ parameters:
                - "~^Function (foreign_keys_sql|recreate_table) not found~" # defined by other drivers
                - "~^Variable \\$(adminer|connection|driver|drivers|error|HTTPS|LANG|langs|permanent|has_token|token|translations|VERSION) might not be defined~" # declared in bootstrap.inc.php
                - "~^Method Adminer\\\\Plugins::\\w+\\(\\) with return type void~" # we use the same pattern for all methods
-               - "~OCI-?Lob~" # maybe include stub?
+               - "~Call to function is_object\\(\\) with Adminer\\\\Db\\|string will always evaluate to false~" # is_object(Db) is true
+               - "~^Comparison operation \"==\" between \\(array\\|float\\|int\\) and 1~" # it thinks that $affected could be an array
 
                # it probably doesn't like $ar[$key] instead of isset($ar[$key]) and thinks that $ar[$key] is always set
-               - "~^Comparison operation \"==\" between \\(array\\|float\\|int\\) and 1~"
+               - identifier: identical.alwaysFalse
+               - identifier: notEqual.alwaysFalse
+               - identifier: notIdentical.alwaysTrue
+               - identifier: booleanNot.alwaysFalse
+               - identifier: booleanAnd.alwaysFalse
+               - identifier: booleanAnd.leftAlwaysTrue
+               - identifier: booleanAnd.rightAlwaysTrue
+               - identifier: booleanAnd.rightAlwaysFalse
+               - identifier: booleanOr.alwaysTrue
+               - identifier: booleanOr.leftAlwaysTrue
+               - identifier: ternary.alwaysTrue
+               - identifier: if.alwaysTrue
+               - identifier: while.alwaysTrue
+               - identifier: isset.offset
+               - identifier: deadCode.unreachable
 
        paths:
                - adminer/
@@ -28,14 +43,14 @@ parameters:
                - adminer/drivers/oracle.inc.php
                - adminer/drivers/pgsql.inc.php
                - adminer/drivers/sqlite.inc.php
-
+       
        phpVersion:
                min: 70100
                max: 80499
        checkMissingCallableSignature: true
        typeAliases:
-               TableStatus: "array{Name:string, Engine?:?string, Comment?:string, Oid?:numeric-string, Rows?:numeric-string, Collation?:string, Auto_increment?:numeric-string, Data_length?:numeric-string, Index_length?:numeric-string, Data_free?:numeric-string, Create_options?:string, nspname?:string}"
-               Field: "array{field:string, full_type:string, type:string, length:numeric-string, unsigned:string, default:?string, null:bool, auto_increment:bool, on_update:string, collation:string, privileges:int[], comment:string, primary:bool, generated:string, orig?:string, on_delete?:string, inout?:string}"
+               TableStatus: "array{Name:string, Engine?:?string, Comment?:string, Oid?:numeric-string, Rows?:?numeric-string, Collation?:string, Auto_increment?:?numeric-string, Data_length?:numeric-string, Index_length?:numeric-string, Data_free?:numeric-string, Create_options?:string, nspname?:string}"
+               Field: "array{field:?string, full_type:string, type:string, length:numeric-string, unsigned:string, default:?string, null:bool, auto_increment:bool, collation:string, privileges:int[], comment:string, primary:bool, generated:string, orig?:string, on_update:?string, on_delete?:string, inout?:string}"
                Index: "array{type:string, columns:list<string>, lengths:list<numeric-string>, 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}"