set annotations/types in af_psql_trgm

This commit is contained in:
Andrew Dolgov 2021-11-14 20:36:55 +03:00
parent d17b79311e
commit cfc31fc692
1 changed files with 14 additions and 19 deletions

View File

@ -202,7 +202,7 @@ class Af_Psql_Trgm extends Plugin {
<?php <?php
/* cleanup */ /* cleanup */
$enabled_feeds = $this->filter_unknown_feeds( $enabled_feeds = $this->filter_unknown_feeds(
$this->get_stored_array("enabled_feeds")); $this->host->get_array($this, "enabled_feeds"));
$this->host->set($this, "enabled_feeds", $enabled_feeds); $this->host->set($this, "enabled_feeds", $enabled_feeds);
?> ?>
@ -227,7 +227,7 @@ class Af_Psql_Trgm extends Plugin {
} }
function hook_prefs_edit_feed($feed_id) { function hook_prefs_edit_feed($feed_id) {
$enabled_feeds = $this->get_stored_array("enabled_feeds"); $enabled_feeds = $this->host->get_array($this, "enabled_feeds");
?> ?>
<header><?= __("Similarity (af_psql_trgm)") ?></header> <header><?= __("Similarity (af_psql_trgm)") ?></header>
@ -244,7 +244,7 @@ class Af_Psql_Trgm extends Plugin {
} }
function hook_prefs_save_feed($feed_id) { function hook_prefs_save_feed($feed_id) {
$enabled_feeds = $this->get_stored_array("enabled_feeds"); $enabled_feeds = $this->host->get_array($this, "enabled_feeds");
$enable = checkbox_to_sql_bool($_POST["trgm_similarity_enabled"] ?? ""); $enable = checkbox_to_sql_bool($_POST["trgm_similarity_enabled"] ?? "");
$key = array_search($feed_id, $enabled_feeds); $key = array_search($feed_id, $enabled_feeds);
@ -273,7 +273,7 @@ class Af_Psql_Trgm extends Plugin {
if (!$enable_globally && if (!$enable_globally &&
!in_array($article["feed"]["id"], !in_array($article["feed"]["id"],
$this->get_stored_array("enabled_feeds"))) { $this->host->get_array($this,"enabled_feeds"))) {
return $article; return $article;
} }
@ -281,14 +281,14 @@ class Af_Psql_Trgm extends Plugin {
$similarity = (float) $this->host->get($this, "similarity", $this->default_similarity); $similarity = (float) $this->host->get($this, "similarity", $this->default_similarity);
if ($similarity < 0.01) { if ($similarity < 0.01) {
Debug::log("af_psql_trgm: similarity is set too low ($similarity)", Debug::$LOG_EXTENDED); Debug::log("af_psql_trgm: similarity is set too low ($similarity)", Debug::LOG_EXTENDED);
return $article; return $article;
} }
$min_title_length = (int) $this->host->get($this, "min_title_length", $this->default_min_length); $min_title_length = (int) $this->host->get($this, "min_title_length", $this->default_min_length);
if (mb_strlen($article["title"]) < $min_title_length) { if (mb_strlen($article["title"]) < $min_title_length) {
Debug::log("af_psql_trgm: article title is too short (min: $min_title_length)", Debug::$LOG_EXTENDED); Debug::log("af_psql_trgm: article title is too short (min: $min_title_length)", Debug::LOG_EXTENDED);
return $article; return $article;
} }
@ -327,10 +327,10 @@ class Af_Psql_Trgm extends Plugin {
$row = $sth->fetch(); $row = $sth->fetch();
$similarity_result = $row['ms']; $similarity_result = $row['ms'];
Debug::log("af_psql_trgm: similarity result for $title_escaped: $similarity_result", Debug::$LOG_EXTENDED); Debug::log("af_psql_trgm: similarity result for $title_escaped: $similarity_result", Debug::LOG_EXTENDED);
if ($similarity_result >= $similarity) { if ($similarity_result >= $similarity) {
Debug::log("af_psql_trgm: marking article as read ($similarity_result >= $similarity)", Debug::$LOG_EXTENDED); Debug::log("af_psql_trgm: marking article as read ($similarity_result >= $similarity)", Debug::LOG_EXTENDED);
$article["force_catchup"] = true; $article["force_catchup"] = true;
} }
@ -342,7 +342,12 @@ class Af_Psql_Trgm extends Plugin {
return 2; return 2;
} }
private function filter_unknown_feeds($enabled_feeds) { /**
* @param array<int> $enabled_feeds
* @return array<int>
* @throws PDOException
*/
private function filter_unknown_feeds($enabled_feeds) : array {
$tmp = array(); $tmp = array();
foreach ($enabled_feeds as $feed) { foreach ($enabled_feeds as $feed) {
@ -357,14 +362,4 @@ class Af_Psql_Trgm extends Plugin {
return $tmp; return $tmp;
} }
private function get_stored_array($name) {
$tmp = $this->host->get($this, $name);
if (!is_array($tmp)) $tmp = [];
return $tmp;
}
} }