Address PHPStan warnings in 'classes/mailer.php', 'classes/opml.php', and 'classes/pluginhandler.php'.

This commit is contained in:
wn_ 2021-11-12 06:16:18 +00:00
parent 9db5e402a0
commit 2c41bc7fbc
3 changed files with 31 additions and 17 deletions

View File

@ -1,8 +1,12 @@
<?php
class Mailer {
private $last_error = "";
private string $last_error = "";
function mail($params) {
/**
* @param array<string, mixed> $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;
}
}

View File

@ -7,6 +7,9 @@ class OPML extends Handler_Protected {
return array_search($method, $csrf_ignored) !== false;
}
/**
* @return bool|int|void false if writing the file failed, true if printing succeeded, int if bytes were written to a file, or void if $owner_uid is missing
*/
function export() {
$output_name = sprintf("tt-rss_%s_%s.opml", $_SESSION["name"], date("Y-m-d"));
$include_settings = $_REQUEST["include_settings"] == "1";
@ -17,7 +20,7 @@ class OPML extends Handler_Protected {
return $rc;
}
function import() {
function import(): void {
$owner_uid = $_SESSION["uid"];
header('Content-Type: text/html; charset=utf-8');
@ -42,13 +45,11 @@ class OPML extends Handler_Protected {
</form>";
print "</div></body></html>";
}
// Export
private function opml_export_category(int $owner_uid, int $cat_id, bool $hide_private_feeds = false, bool $include_settings = true) {
private function opml_export_category(int $owner_uid, int $cat_id, bool $hide_private_feeds = false, bool $include_settings = true): string {
if ($hide_private_feeds)
$hide_qpart = "(private IS false AND auth_login = '' AND auth_pass = '')";
@ -124,6 +125,9 @@ class OPML extends Handler_Protected {
return $out;
}
/**
* @return bool|int|void false if writing the file failed, true if printing succeeded, int if bytes were written to a file, or void if $owner_uid is missing
*/
function opml_export(string $filename, int $owner_uid, bool $hide_private_feeds = false, bool $include_settings = true, bool $file_output = false) {
if (!$owner_uid) return;
@ -290,13 +294,14 @@ class OPML extends Handler_Protected {
if ($file_output)
return file_put_contents($filename, $res) > 0;
else
print $res;
print $res;
return true;
}
// Import
private function opml_import_feed(DOMNode $node, int $cat_id, int $owner_uid, int $nest) {
private function opml_import_feed(DOMNode $node, int $cat_id, int $owner_uid, int $nest): void {
$attrs = $node->attributes;
$feed_title = mb_substr($attrs->getNamedItem('text')->nodeValue, 0, 250);
@ -341,7 +346,7 @@ class OPML extends Handler_Protected {
}
}
private function opml_import_label(DOMNode $node, int $owner_uid, int $nest) {
private function opml_import_label(DOMNode $node, int $owner_uid, int $nest): void {
$attrs = $node->attributes;
$label_name = $attrs->getNamedItem('label-name')->nodeValue;
@ -358,7 +363,7 @@ class OPML extends Handler_Protected {
}
}
private function opml_import_preference(DOMNode $node, int $owner_uid, int $nest) {
private function opml_import_preference(DOMNode $node, int $owner_uid, int $nest): void {
$attrs = $node->attributes;
$pref_name = $attrs->getNamedItem('pref-name')->nodeValue;
@ -372,7 +377,7 @@ class OPML extends Handler_Protected {
}
}
private function opml_import_filter(DOMNode $node, int $owner_uid, int $nest) {
private function opml_import_filter(DOMNode $node, int $owner_uid, int $nest): void {
$attrs = $node->attributes;
$filter_type = $attrs->getNamedItem('filter-type')->nodeValue;
@ -526,7 +531,7 @@ class OPML extends Handler_Protected {
}
}
private function opml_import_category(DOMDocument $doc, ?DOMNode $root_node, int $owner_uid, int $parent_id, int $nest) {
private function opml_import_category(DOMDocument $doc, ?DOMNode $root_node, int $owner_uid, int $parent_id, int $nest): void {
$default_cat_id = (int) $this->get_feed_category('Imported feeds', $owner_uid, 0);
if ($root_node) {
@ -601,6 +606,9 @@ class OPML extends Handler_Protected {
}
/** $filename is optional; assumes HTTP upload with $_FILES otherwise */
/**
* @return bool|void false on failure, true if successful, void if $owner_uid is missing
*/
function opml_import(int $owner_uid, string $filename = "") {
if (!$owner_uid) return;
@ -667,7 +675,7 @@ class OPML extends Handler_Protected {
return true;
}
private function opml_notice(string $msg, int $prefix_length = 0) {
private function opml_notice(string $msg, int $prefix_length = 0): void {
if (php_sapi_name() == "cli") {
Debug::log(str_repeat(" ", $prefix_length) . $msg);
} else {

View File

@ -4,7 +4,7 @@ class PluginHandler extends Handler_Protected {
return true;
}
function catchall($method) {
function catchall(string $method): void {
$plugin_name = clean($_REQUEST["plugin"]);
$plugin = PluginHost::getInstance()->get_plugin($plugin_name);
$csrf_token = ($_POST["csrf_token"] ?? "");