From c48dd6a3c4f68d1a3980bfed0d4d827fada92c32 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 5 Mar 2023 14:02:26 +0000 Subject: Address PHPStan 'right side always true' in FeedItem_RSS. --- classes/feeditem/rss.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'classes') diff --git a/classes/feeditem/rss.php b/classes/feeditem/rss.php index e07fd1d06..b5710ef4f 100755 --- a/classes/feeditem/rss.php +++ b/classes/feeditem/rss.php @@ -84,15 +84,6 @@ class FeedItem_RSS extends FeedItem_Common { /** @var DOMElement|null */ $contentB = $this->elem->getElementsByTagName("description")->item(0); - if ($contentA && !$contentB) { - return $this->subtree_or_text($contentA); - } - - - if ($contentB && !$contentA) { - return $this->subtree_or_text($contentB); - } - if ($contentA && $contentB) { $resultA = $this->subtree_or_text($contentA); $resultB = $this->subtree_or_text($contentB); @@ -100,6 +91,14 @@ class FeedItem_RSS extends FeedItem_Common { return mb_strlen($resultA) > mb_strlen($resultB) ? $resultA : $resultB; } + if ($contentA) { + return $this->subtree_or_text($contentA); + } + + if ($contentB) { + return $this->subtree_or_text($contentB); + } + return ''; } -- cgit v1.2.3-54-g00ecf From c4b16ca6085f30d69669009dcf75e3cbf8391cb8 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 5 Mar 2023 14:08:10 +0000 Subject: Address PHPStan 'right side always true' in 'PluginHost::lookup_command()'. Since 'PluginHost::add_command()' is currently the only way to add to this private array, and it always sets an array, this is reasonably safe. --- classes/pluginhost.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 1159e8ed1..9e3cf1ba1 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -588,7 +588,7 @@ class PluginHost { function lookup_command(string $command) { $command = "-" . strtolower($command); - if (array_key_exists($command, $this->commands) && is_array($this->commands[$command])) { + if (array_key_exists($command, $this->commands)) { return $this->commands[$command]["class"]; } else { return false; -- cgit v1.2.3-54-g00ecf From 7ed4fa4c1dbdd9df552cf6dd28907c6769911a0e Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 5 Mar 2023 14:09:20 +0000 Subject: Tweak to appease PHPStan in 'Pref_Feeds::_makefeedtree()'. PHPStan flagged the 'count()' below this with: Comparison operation '>' between 0 and 0 is always false. --- classes/pref/feeds.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 679eb12e9..d8b2ba01a 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -267,7 +267,7 @@ class Pref_Feeds extends Handler_Protected { } foreach ($feeds_obj->find_many() as $feed) { - array_push($cat['items'], [ + $cat['items'][] = [ 'id' => 'FEED:' . $feed->id, 'bare_id' => (int) $feed->id, 'auxcounter' => -1, @@ -279,7 +279,7 @@ class Pref_Feeds extends Handler_Protected { 'unread' => -1, 'type' => 'feed', 'updates_disabled' => (int)($feed->update_interval < 0), - ]); + ]; } $cat['param'] = sprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); -- cgit v1.2.3-54-g00ecf From dabb85c7dd82d2e97e400e0339d312030d4a1b4b Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 5 Mar 2023 14:10:38 +0000 Subject: Address PHPStan warning about unused private method 'Prefs::_delete()'. --- classes/prefs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/prefs.php b/classes/prefs.php index 378fea293..92f703b3f 100644 --- a/classes/prefs.php +++ b/classes/prefs.php @@ -325,13 +325,13 @@ class Prefs { return self::get_instance()->_set($pref_name, $value, $owner_uid, $profile_id); } - private function _delete(string $pref_name, int $owner_uid, ?int $profile_id): bool { + /* private function _delete(string $pref_name, int $owner_uid, ?int $profile_id): bool { $sth = $this->pdo->prepare("DELETE FROM ttrss_user_prefs2 WHERE pref_name = :name AND owner_uid = :uid AND (profile = :profile OR (:profile IS NULL AND profile IS NULL))"); return $sth->execute(["uid" => $owner_uid, "profile" => $profile_id, "name" => $pref_name ]); - } + } */ /** * @param bool|int|string $value -- cgit v1.2.3-54-g00ecf From 42b287e9646c61f4f62b3d44c5ab6897c4c6bf06 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 5 Mar 2023 15:30:09 +0000 Subject: Remove unused 'Prefs::_delete()'. Related to dabb85c7dd82d2e97e400e0339d312030d4a1b4b. --- classes/prefs.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'classes') diff --git a/classes/prefs.php b/classes/prefs.php index 92f703b3f..9d68a14b7 100644 --- a/classes/prefs.php +++ b/classes/prefs.php @@ -325,14 +325,6 @@ class Prefs { return self::get_instance()->_set($pref_name, $value, $owner_uid, $profile_id); } - /* private function _delete(string $pref_name, int $owner_uid, ?int $profile_id): bool { - $sth = $this->pdo->prepare("DELETE FROM ttrss_user_prefs2 - WHERE pref_name = :name AND owner_uid = :uid AND - (profile = :profile OR (:profile IS NULL AND profile IS NULL))"); - - return $sth->execute(["uid" => $owner_uid, "profile" => $profile_id, "name" => $pref_name ]); - } */ - /** * @param bool|int|string $value */ @@ -350,10 +342,6 @@ class Prefs { $value = Config::cast_to($value, $type_hint); - // is this a good idea or not? probably not (user-set value remains user-set even if its at default) - //if ($value == $def_val) - // return $this->_delete($pref_name, $owner_uid, $profile_id); - if ($value == $this->_get($pref_name, $owner_uid, $profile_id)) return false; -- cgit v1.2.3-54-g00ecf From 029cb8f4420a99aef225413f3c32ec1db35717a8 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 5 Mar 2023 16:29:51 +0000 Subject: Revert 7ed4fa4c1dbdd9df552cf6dd28907c6769911a0e and use @var instead. PHPStan had trouble recognizing that ['items'] might have elements added. --- classes/pref/feeds.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'classes') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index d8b2ba01a..36dfbef76 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -241,7 +241,12 @@ class Pref_Feeds extends Handler_Protected { //$root['param'] += count($cat['items']); } - /* Uncategorized is a special case */ + /** + * Uncategorized is a special case. + * + * Define a minimal array shape to help PHPStan with the type of $cat['items'] + * @var array{items: array>} $cat + */ $cat = [ 'id' => 'CAT:0', 'bare_id' => 0, @@ -267,7 +272,7 @@ class Pref_Feeds extends Handler_Protected { } foreach ($feeds_obj->find_many() as $feed) { - $cat['items'][] = [ + array_push($cat['items'], [ 'id' => 'FEED:' . $feed->id, 'bare_id' => (int) $feed->id, 'auxcounter' => -1, @@ -279,7 +284,7 @@ class Pref_Feeds extends Handler_Protected { 'unread' => -1, 'type' => 'feed', 'updates_disabled' => (int)($feed->update_interval < 0), - ]; + ]); } $cat['param'] = sprintf(_ngettext('(%d feed)', '(%d feeds)', count($cat['items'])), count($cat['items'])); -- cgit v1.2.3-54-g00ecf