From 1ad184641db35b8c20cb374c1c8360ef86af6bc7 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 31 Jan 2020 16:30:46 +0000 Subject: [PATCH] php7.4 / psalm fixes --- composer.json | 2 +- functions.inc.php | 1 + lib/block_random_int.php | 2 +- model/AliasHandler.php | 2 +- model/CliEdit.php | 2 +- model/MailboxHandler.php | 2 +- model/PFAHandler.php | 7 ++----- model/Shell.php | 1 + public/index.php | 3 +++ 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 33cd3344..20f85618 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "jakub-onderka/php-parallel-lint": "^1.0", "php": ">7.2.0", "php-coveralls/php-coveralls" : "*", - "phpunit/phpunit": "^6.0", + "phpunit/phpunit": "^6|^7", "vimeo/psalm":"^3.0", "zendframework/zendframework1": "^1.12.0" }, diff --git a/functions.inc.php b/functions.inc.php index db4472c9..6929379e 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1721,6 +1721,7 @@ function db_query($sql, array $values = array(), $ignore_errors = false) { $link = db_connect(); $error_text = ''; + $stmt = null; try { $stmt = $link->prepare($sql); $stmt->execute($values); diff --git a/lib/block_random_int.php b/lib/block_random_int.php index 765107e8..5d6d9d0b 100644 --- a/lib/block_random_int.php +++ b/lib/block_random_int.php @@ -12,6 +12,6 @@ if(function_exists('random_int')) { return; } -function random_int() { // someone might not be using php_crypt or ask for password generation, in which case random_int() won't be called +function random_int($a, $b) { // someone might not be using php_crypt or ask for password generation, in which case random_int() won't be called die(__FILE__ . " Postfixadmin security: Please install https://github.com/paragonie/random_compat OR enable the 'Phar' extension."); } diff --git a/model/AliasHandler.php b/model/AliasHandler.php index b52c835f..619d2834 100644 --- a/model/AliasHandler.php +++ b/model/AliasHandler.php @@ -139,7 +139,7 @@ class AliasHandler extends PFAHandler { public function init($id) { @list($local_part, $domain) = explode('@', $id); # supress error message if $id doesn't contain '@' - if ($local_part == '*') { # catchall - postfix expects '@domain', not '*@domain' + if ($local_part == '*' && !is_null($domain)) { # catchall - postfix expects '@domain', not '*@domain' $id = '@' . $domain; } diff --git a/model/CliEdit.php b/model/CliEdit.php index f39bba1d..2f2153b7 100644 --- a/model/CliEdit.php +++ b/model/CliEdit.php @@ -46,7 +46,7 @@ class CliEdit extends Shell { if (strtolower($val) == 'y') { $val = 1; } # convert y to 1 - if (strtolower($val) == 'n') { + elseif (strtolower($val) == 'n') { $val = 0; } # convert n to 0 $values[$key] = $val; # don't modify any other value - *Handler will complain if it's invalid ;-) diff --git a/model/MailboxHandler.php b/model/MailboxHandler.php index 6c6c7e6d..c472d9be 100644 --- a/model/MailboxHandler.php +++ b/model/MailboxHandler.php @@ -586,7 +586,7 @@ class MailboxHandler extends PFAHandler { if ($quota <= 0) { $quota = 0; } # TODO: check if this is correct behaviour - $cmdarg4=escapeshellarg($quota); + $cmdarg4 = escapeshellarg("" . $quota); $command= "$cmd $cmdarg1 $cmdarg2 $cmdarg3 $cmdarg4"; $retval=0; $output=array(); diff --git a/model/PFAHandler.php b/model/PFAHandler.php index 7a11c938..c85b110d 100644 --- a/model/PFAHandler.php +++ b/model/PFAHandler.php @@ -168,10 +168,10 @@ abstract class PFAHandler { */ public function __construct($new = 0, $username = "", $is_admin = 1) { # set label_field if not explicitely set - if (!isset($this->id_field)) { + if (empty($this->id_field)) { throw new \InvalidArgumentException("id_field must be defined"); } - if (!isset($this->db_table)) { + if (empty($this->db_table)) { throw new \InvalidArgumentException("db_table must be defined"); } if (empty($this->label_field)) { @@ -237,9 +237,6 @@ abstract class PFAHandler { ); } - if (empty($this->db_table)) { - throw new Exception("db_table not defined"); - } $struct_hook = Config::read_string($this->db_table . '_struct_hook'); if (!empty($struct_hook) && is_string($struct_hook) && $struct_hook != 'NO' && function_exists($struct_hook)) { $this->struct = $struct_hook($this->struct); diff --git a/model/Shell.php b/model/Shell.php index 09fbaaa4..4a30f496 100644 --- a/model/Shell.php +++ b/model/Shell.php @@ -97,6 +97,7 @@ class Shell { */ public $handler_to_use; + public $new; /** * Constructs this Shell instance. * diff --git a/public/index.php b/public/index.php index 352c4ff6..1554a10d 100644 --- a/public/index.php +++ b/public/index.php @@ -28,6 +28,9 @@ if (file_exists(dirname(__FILE__) . '/../config.inc.php')) { require_once(dirname(__FILE__) . '/../config.inc.php'); } +/** + * @psalm-suppress TypeDoesNotContainType + */ if ($CONF['configured']) { header("Location: login.php"); exit;