From 618e96b793769ef4d7912f1f16f1ca7436acd199 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 13 Nov 2021 19:55:30 +0300 Subject: deal with some warnings in plugins/trgm,readability and base plugin class --- plugins/af_readability/init.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugins/af_readability/init.php') diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index a39cc278e..05b229eae 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -6,7 +6,7 @@ use \andreskrey\Readability\Configuration; class Af_Readability extends Plugin { - /* @var PluginHost $host */ + /** @var PluginHost $host */ private $host; function about() { @@ -19,6 +19,7 @@ class Af_Readability extends Plugin { return array("needs_curl" => true); } + /** @return void */ function save() { $enable_share_anything = checkbox_to_sql_bool($_POST["enable_share_anything"] ?? ""); -- cgit v1.2.3-54-g00ecf From dd7299b6d070d26ff97194ef14be349f08776e2a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Nov 2021 17:19:35 +0300 Subject: deal with a few more phpstan warnings re: base plugin class --- classes/plugin.php | 48 ++++++++++++++++++++++++++++++++++++++++- plugins/af_readability/init.php | 1 + 2 files changed, 48 insertions(+), 1 deletion(-) (limited to 'plugins/af_readability/init.php') diff --git a/classes/plugin.php b/classes/plugin.php index 96541d033..ac234f081 100644 --- a/classes/plugin.php +++ b/classes/plugin.php @@ -226,8 +226,18 @@ abstract class Plugin { return ""; } + /** + * @param DOMDocument $doc + * @param string $site_url + * @param array $allowed_elements + * @param array $disallowed_attributes + * @param int $article_id + * @return DOMDocument + */ function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id) { user_error("Dummy method invoked.", E_USER_ERROR); + + return $doc; } /** @@ -301,8 +311,20 @@ abstract class Plugin { user_error("Dummy method invoked.", E_USER_ERROR); } + /** + * @param string $feed_data + * @param string $fetch_url + * @param int $owner_uid + * @param int $feed + * @param int $last_article_timestamp + * @param string $auth_login + * @param string $auth_pass + * @return string (possibly mangled feed data) + */ function hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, $last_article_timestamp, $auth_login, $auth_pass) { user_error("Dummy method invoked.", E_USER_ERROR); + + return ""; } /** @@ -331,8 +353,19 @@ abstract class Plugin { return []; } - function hook_format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images) { + /** + * @param string $enclosures_formatted + * @param array> $enclosures + * @param int $article_id + * @param bool $always_display_enclosures + * @param string $article_content + * @param bool $hide_images + * @return string|array>> ($enclosures_formatted, $enclosures) + */ + function hook_format_enclosures($enclosures_formatted, $enclosures, $article_id, $always_display_enclosures, $article_content, $hide_images) { user_error("Dummy method invoked.", E_USER_ERROR); + + return ""; } /** @@ -344,6 +377,8 @@ abstract class Plugin { */ function hook_subscribe_feed($contents, $url, $auth_login, $auth_pass) { user_error("Dummy method invoked.", E_USER_ERROR); + + return ""; } /** @@ -366,10 +401,19 @@ abstract class Plugin { */ function hook_render_enclosure($entry, $article_id, $rv) { user_error("Dummy method invoked.", E_USER_ERROR); + + return ""; } + /** + * @param array $article + * @param string $action + * @return array ($article) + */ function hook_article_filter_action($article, $action) { user_error("Dummy method invoked.", E_USER_ERROR); + + return []; } /** @@ -409,6 +453,8 @@ abstract class Plugin { */ function hook_format_article($html, $row) { user_error("Dummy method invoked.", E_USER_ERROR); + + return ""; } function hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed_id, $auth_login, $auth_pass) { diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index 05b229eae..8e75d0c2e 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -187,6 +187,7 @@ class Af_Readability extends Plugin { case "action_append": return $this->process_article($article, true); } + return $article; } public function extract_content($url) { -- cgit v1.2.3-54-g00ecf From c3fbf56984477393669727a296ec229c8d303fbf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Nov 2021 21:25:56 +0300 Subject: deal with most of warnings in plugins/af_readability --- plugins/af_readability/init.php | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'plugins/af_readability/init.php') diff --git a/plugins/af_readability/init.php b/plugins/af_readability/init.php index 8e75d0c2e..a13f2a5b2 100755 --- a/plugins/af_readability/init.php +++ b/plugins/af_readability/init.php @@ -190,7 +190,11 @@ class Af_Readability extends Plugin { return $article; } - public function extract_content($url) { + /** + * @param string $url + * @return string|false + */ + public function extract_content(string $url) { $tmp = UrlHelper::fetch([ "url" => $url, @@ -224,13 +228,13 @@ class Af_Readability extends Plugin { foreach ($entries as $entry) { if ($entry->hasAttribute("href")) { $entry->setAttribute("href", - rewrite_relative_url(UrlHelper::$fetch_effective_url, $entry->getAttribute("href"))); + UrlHelper::rewrite_relative(UrlHelper::$fetch_effective_url, $entry->getAttribute("href"))); } if ($entry->hasAttribute("src")) { $entry->setAttribute("src", - rewrite_relative_url(UrlHelper::$fetch_effective_url, $entry->getAttribute("src"))); + UrlHelper::rewrite_relative(UrlHelper::$fetch_effective_url, $entry->getAttribute("src"))); } } @@ -246,7 +250,13 @@ class Af_Readability extends Plugin { return false; } - function process_article($article, $append_mode) { + /** + * @param array $article + * @param bool $append_mode + * @return array + * @throws PDOException + */ + function process_article(array $article, bool $append_mode) : array { $extracted_content = $this->extract_content($article["link"]); @@ -263,12 +273,14 @@ class Af_Readability extends Plugin { return $article; } - private function get_stored_array($name) { - $tmp = $this->host->get($this, $name); - - if (!is_array($tmp)) $tmp = []; - - return $tmp; + /** + * @param string $name + * @return array + * @throws PDOException + * @deprecated + */ + private function get_stored_array(string $name) : array { + return $this->host->get_array($this, $name); } function hook_article_filter($article) { @@ -306,7 +318,12 @@ class Af_Readability extends Plugin { return 2; } - private function filter_unknown_feeds($enabled_feeds) { + /** + * @param array $enabled_feeds + * @return array + * @throws PDOException + */ + private function filter_unknown_feeds(array $enabled_feeds) : array { $tmp = array(); foreach ($enabled_feeds as $feed) { @@ -322,7 +339,7 @@ class Af_Readability extends Plugin { return $tmp; } - function embed() { + function embed() : void { $article_id = (int) $_REQUEST["id"]; $sth = $this->pdo->prepare("SELECT link FROM ttrss_entries WHERE id = ?"); -- cgit v1.2.3-54-g00ecf