From 2c41bc7fbc9013e79e929a31e3824cf040afc54a Mon Sep 17 00:00:00 2001 From: wn_ Date: Fri, 12 Nov 2021 06:16:18 +0000 Subject: Address PHPStan warnings in 'classes/mailer.php', 'classes/opml.php', and 'classes/pluginhandler.php'. --- classes/mailer.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'classes/mailer.php') diff --git a/classes/mailer.php b/classes/mailer.php index 8238904ee..4eb13aec8 100644 --- a/classes/mailer.php +++ b/classes/mailer.php @@ -1,8 +1,12 @@ $params + * @return bool|int bool if the default mail function handled the request, otherwise an int as described in Mailer#mail() + */ + function mail(array $params) { $to_name = $params["to_name"] ?? ""; $to_address = $params["to_address"]; @@ -26,6 +30,8 @@ class Mailer { // 4. set error message if needed via passed Mailer instance function set_error() foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { + // Implemented via plugin, so ignore the undefined method 'hook_send_mail'. + // @phpstan-ignore-next-line $rc = $p->hook_send_mail($this, $params); if ($rc == 1) @@ -46,12 +52,12 @@ class Mailer { return $rc; } - function set_error($message) { + function set_error(string $message): void { $this->last_error = $message; user_error("Error sending mail: $message", E_USER_WARNING); } - function error() { + function error(): string { return $this->last_error; } } -- cgit v1.2.3-54-g00ecf From d3a81f598b24d6ae4f98415fac9509df6749eaf8 Mon Sep 17 00:00:00 2001 From: wn_ Date: Fri, 12 Nov 2021 21:17:31 +0000 Subject: Switch class properties from PHP typing to PHPDoc for compatibility with PHP < 7.4.0 --- classes/db/migrations.php | 37 ++++++++++++++++++++++++++---------- classes/debug.php | 48 ++++++++++++++++++++++++++++++++--------------- classes/diskcache.php | 4 +++- classes/mailer.php | 4 +++- classes/pluginhost.php | 41 +++++++++++++++++++++++++--------------- classes/urlhelper.php | 32 +++++++++++++++++++++++-------- 6 files changed, 116 insertions(+), 50 deletions(-) (limited to 'classes/mailer.php') diff --git a/classes/db/migrations.php b/classes/db/migrations.php index cb74c247a..6e20ddf7f 100644 --- a/classes/db/migrations.php +++ b/classes/db/migrations.php @@ -1,16 +1,33 @@ pdo = Db::pdo(); diff --git a/classes/debug.php b/classes/debug.php index 6e8c46ed2..e20126b86 100644 --- a/classes/debug.php +++ b/classes/debug.php @@ -1,9 +1,9 @@ $params diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 36e050377..173a75611 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -1,38 +1,49 @@ >> hook types -> priority levels -> Plugins */ - private array $hooks = []; + private $hooks = []; /** @var array */ - private array $plugins = []; + private $plugins = []; /** @var array> handler type -> method type -> Plugin */ - private array $handlers = []; + private $handlers = []; /** @var array command type -> details array */ - private array $commands = []; + private $commands = []; /** @var array> plugin name -> (potential profile array) -> key -> value */ - private array $storage = []; + private $storage = []; /** @var array> */ - private array $feeds = []; + private $feeds = []; /** @var array API method name, Plugin sender */ - private array $api_methods = []; + private $api_methods = []; /** @var array> */ - private array $plugin_actions = []; + private $plugin_actions = []; + + /** @var int|null */ + private $owner_uid = null; + + /** @var bool */ + private $data_loaded = false; - private ?int $owner_uid = null; - private bool $data_loaded = false; - private static ?PluginHost $instance = null; + /** @var PluginHost|null */ + private static $instance = null; const API_VERSION = 2; const PUBLIC_METHOD_DELIMITER = "--"; diff --git a/classes/urlhelper.php b/classes/urlhelper.php index 0592bf28c..351d66b8d 100644 --- a/classes/urlhelper.php +++ b/classes/urlhelper.php @@ -6,14 +6,30 @@ class UrlHelper { "tel" ]; - static string $fetch_last_error; - static int $fetch_last_error_code; - static string $fetch_last_error_content; - static string $fetch_last_content_type; - static string $fetch_last_modified; - static string $fetch_effective_url; - static string $fetch_effective_ip_addr; - static bool $fetch_curl_used; + // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+ + /** @var string */ + static $fetch_last_error; + + /** @var int */ + static $fetch_last_error_code; + + /** @var string */ + static $fetch_last_error_content; + + /** @var string */ + static $fetch_last_content_type; + + /** @var string */ + static $fetch_last_modified; + + /** @var string */ + static $fetch_effective_url; + + /** @var string */ + static $fetch_effective_ip_addr; + + /** @var bool */ + static $fetch_curl_used; /** * @param array $parts -- cgit v1.2.3-54-g00ecf From 812f5f532e73fe2a9a9aabc4c5bec97b71f5993a Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 14 Nov 2021 17:57:17 +0000 Subject: Address PHPStan warning in 'classes/mailer.php'. --- classes/mailer.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'classes/mailer.php') diff --git a/classes/mailer.php b/classes/mailer.php index a0f232800..339b2895a 100644 --- a/classes/mailer.php +++ b/classes/mailer.php @@ -32,8 +32,6 @@ class Mailer { // 4. set error message if needed via passed Mailer instance function set_error() foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { - // Implemented via plugin, so ignore the undefined method 'hook_send_mail'. - // @phpstan-ignore-next-line $rc = $p->hook_send_mail($this, $params); if ($rc == 1) -- cgit v1.2.3-54-g00ecf From 6a8030fd76f154097b4aa4acbfcec5465fb1aece Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 16 Nov 2021 09:19:12 +0300 Subject: mailer: don't crash if php mail() fails with no reported errors --- classes/mailer.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'classes/mailer.php') diff --git a/classes/mailer.php b/classes/mailer.php index 339b2895a..60b1ce4fd 100644 --- a/classes/mailer.php +++ b/classes/mailer.php @@ -31,6 +31,8 @@ class Mailer { // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function // 4. set error message if needed via passed Mailer instance function set_error() + $hooks_tried = 0; + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) { $rc = $p->hook_send_mail($this, $params); @@ -39,6 +41,8 @@ class Mailer { if ($rc == -1) return 0; + + ++$hooks_tried; } $headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ]; @@ -46,7 +50,7 @@ class Mailer { $rc = mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); if (!$rc) { - $this->set_error(error_get_last()['message']); + $this->set_error(error_get_last()['message'] ?? T_sprintf("Unknown error while sending mail. Hooks tried: %d.", $hooks_tried)); } return $rc; -- cgit v1.2.3-54-g00ecf