From 63c258a7f9bb9972607dd4cc85210b287d86b0c7 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 26 Mar 2025 12:41:52 +0100 Subject: [PATCH] PHPStan: Fix level 0 errors --- adminer/drivers/mysql.inc.php | 2 +- adminer/drivers/pgsql.inc.php | 4 +--- adminer/include/adminer.inc.php | 4 ++-- adminer/include/driver.inc.php | 11 +++++------ adminer/include/editing.inc.php | 2 +- adminer/include/functions.inc.php | 16 ++++++++-------- phpstan.neon | 13 +++++++++++++ plugins/drivers/firebird.php | 4 ++-- plugins/drivers/imap.php | 4 ++-- plugins/drivers/mongo.php | 2 +- 10 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 phpstan.neon diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 05436fe0..a44da959 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -1184,7 +1184,7 @@ if (!defined('Adminer\DRIVER')) { /** Convert field in select and edit * @param Field one element from fields() - * @return string + * @return ?string */ function convert_field($field) { if (preg_match("~binary~", $field["type"])) { diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index bad69c47..3e278b15 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -176,9 +176,7 @@ if (isset($_GET["pgsql"])) { return $return; } - function warnings() { - return ''; // not implemented in PDO_PgSQL as of PHP 7.2.1 - } + // warnings() not implemented in PDO_PgSQL as of PHP 7.2.1 function close() { } diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 58dddf57..0a3a9b23 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -22,7 +22,7 @@ class Adminer { } /** Get SSL connection options - * @return string[] or null + * @return ?string[] */ function connectSsl() { } @@ -289,7 +289,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 or null to create the default link + * @return ?string null to create the default link */ function selectLink($val, $field) { } diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index 1ea97a6a..b7f5f3bb 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -61,14 +61,14 @@ abstract class SqlDriver { /** Get enum values * @param Field - * @return string or null + * @return ?string */ function enumLength($field) { } /** Function used to convert the value inputted by user * @param Field - * @return string or null + * @return ?string */ function unconvertFunction($field) { } @@ -187,7 +187,7 @@ abstract class SqlDriver { /** Return query with a timeout * @param string * @param int seconds - * @return string or null if the driver doesn't support query timeouts + * @return ?string null if the driver doesn't support query timeouts */ function slowQuery($query, $timeout) { } @@ -231,16 +231,15 @@ abstract class SqlDriver { } /** Get warnings about the last command - * @return string HTML + * @return ?string HTML */ function warnings() { - return ''; } /** Get help link for table * @param string * @param bool - * @return string relative URL or null + * @return ?string relative URL */ function tableHelp($name, $is_view = false) { } diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index de12030e..005db513 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -299,7 +299,7 @@ function default_value($field) { /** Get type class to use in CSS * @param string -* @return string class='' +* @return ?string class='' */ function type_class($type) { foreach ( diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 073bda50..c23a0c3f 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -66,8 +66,8 @@ function escape_string($val) { } /** Get a possibly missing item from a possibly missing array -* idx($row, $key) is better than $row[$key] ?? null because it reports error for undefined $row -* @param array|null +* idx($row, $key) is better than $row[$key] ?? null because PHP will report error for undefined $row +* @param ?array * @param string|int * @param mixed * @return mixed @@ -274,7 +274,7 @@ function get_rows($query, $connection2 = null, $error = "

") { /** Find unique identifier of a row * @param string[] * @param Index[] result of indexes() -* @return string[] or null if there is no unique identifier +* @return ?string[] null if there is no unique identifier */ function unique_array($row, $indexes) { foreach ($indexes as $index) { @@ -377,11 +377,11 @@ function convert_fields($columns, $fields, $select = array()) { * @param string * @param string * @param int number of seconds, 0 for session cookie, 2592000 - 30 days -* @return bool +* @return null */ function cookie($name, $value, $lifetime = 2592000) { global $HTTPS; - return header( + header( "Set-Cookie: $name=" . urlencode($value) . ($lifetime ? "; expires=" . gmdate("D, d M Y H:i:s", time() + $lifetime) . " GMT" : "") . "; path=" . preg_replace('~\?.*~', '', $_SERVER["REQUEST_URI"]) @@ -413,10 +413,10 @@ function get_setting($key, $cookie = "adminer_settings") { /** Store settings to a cookie * @param mixed[] * @param string -* @return bool +* @return null */ function save_settings($settings, $cookie = "adminer_settings") { - return cookie($cookie, http_build_query($settings + get_settings($cookie))); + cookie($cookie, http_build_query($settings + get_settings($cookie))); } /** Restart stopped session @@ -495,7 +495,7 @@ function is_ajax() { /** Send Location header and exit * @param string null to only set a message * @param string -* @return never +* @return null */ function redirect($location, $message = null) { if ($message !== null) { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..3a9be1bb --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,13 @@ +parameters: + level: 0 + 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 + paths: + - . + phpVersion: + min: 70100 + max: 80499 + checkMissingCallableSignature: true diff --git a/plugins/drivers/firebird.php b/plugins/drivers/firebird.php index e8a6d58a..0bde0c75 100644 --- a/plugins/drivers/firebird.php +++ b/plugins/drivers/firebird.php @@ -27,8 +27,8 @@ if (isset($_GET["firebird"])) { $this->_link = ibase_connect($server, $username, $password); if ($this->_link) { $url_parts = explode(':', $server); - $this->service_link = ibase_service_attach($url_parts[0], $username, $password); - $this->server_info = ibase_server_info($this->service_link, IBASE_SVC_SERVER_VERSION); + $service_link = ibase_service_attach($url_parts[0], $username, $password); + $this->server_info = ibase_server_info($service_link, IBASE_SVC_SERVER_VERSION); } else { $this->errno = ibase_errcode(); $this->error = ibase_errmsg(); diff --git a/plugins/drivers/imap.php b/plugins/drivers/imap.php index 9583ac69..ad6f3c02 100644 --- a/plugins/drivers/imap.php +++ b/plugins/drivers/imap.php @@ -110,7 +110,7 @@ if (isset($_GET["imap"])) { } function expunge() { - return imap_expunge(); + return imap_expunge($this->imap); } } @@ -272,7 +272,7 @@ if (isset($_GET["imap"])) { } function truncate_tables($tables) { - return connection()->expunge($name); + return connection()->expunge(); } function connect($credentials) { diff --git a/plugins/drivers/mongo.php b/plugins/drivers/mongo.php index fc745968..55abb3f1 100644 --- a/plugins/drivers/mongo.php +++ b/plugins/drivers/mongo.php @@ -19,7 +19,7 @@ if (isset($_GET["mongo"])) { } function executeCommand($command) { - return $this->executeDbCommand($this->_db_name); + return $this->executeDbCommand($this->_db_name, $command); } function executeDbCommand($db, $command) {