From 14ca0f2ac01c4ff9ffa27387326c6ebe5f002005 Mon Sep 17 00:00:00 2001 From: wn_ Date: Thu, 11 Nov 2021 12:26:30 +0000 Subject: Address PHPStan warnings in 'classes/counters.php'. --- classes/counters.php | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) (limited to 'classes/counters.php') diff --git a/classes/counters.php b/classes/counters.php index 8a8b8bc71..1375a6694 100644 --- a/classes/counters.php +++ b/classes/counters.php @@ -1,7 +1,10 @@ > + */ + static function get_all(): array { return array_merge( self::get_global(), self::get_virt(), @@ -11,7 +14,12 @@ class Counters { ); } - static function get_conditional(array $feed_ids = null, array $label_ids = null) { + /** + * @param array $feed_ids + * @param array $label_ids + * @return array> + */ + static function get_conditional(array $feed_ids = null, array $label_ids = null): array { return array_merge( self::get_global(), self::get_virt(), @@ -21,7 +29,10 @@ class Counters { ); } - static private function get_cat_children(int $cat_id, int $owner_uid) { + /** + * @return array + */ + static private function get_cat_children(int $cat_id, int $owner_uid): array { $unread = 0; $marked = 0; @@ -40,7 +51,11 @@ class Counters { return [$unread, $marked]; } - private static function get_cats(array $cat_ids = null) { + /** + * @param array $cat_ids + * @return array> + */ + private static function get_cats(array $cat_ids = null): array { $ret = []; /* Labels category */ @@ -129,7 +144,11 @@ class Counters { return $ret; } - private static function get_feeds(array $feed_ids = null) { + /** + * @param array $feed_ids + * @return array> + */ + private static function get_feeds(array $feed_ids = null): array { $ret = []; @@ -199,7 +218,10 @@ class Counters { return $ret; } - private static function get_global() { + /** + * @return array> + */ + private static function get_global(): array { $ret = [ [ "id" => "global-unread", @@ -219,7 +241,10 @@ class Counters { return $ret; } - private static function get_virt() { + /** + * @return array> + */ + private static function get_virt(): array { $ret = []; @@ -263,7 +288,11 @@ class Counters { return $ret; } - static function get_labels(array $label_ids = null) { + /** + * @param array $label_ids + * @return array> + */ + static function get_labels(array $label_ids = null): array { $ret = []; -- cgit v1.2.3-54-g00ecf From b0eb347839d3350b57bd614eee67e32a574661d5 Mon Sep 17 00:00:00 2001 From: wn_ Date: Fri, 12 Nov 2021 05:04:55 +0000 Subject: Fix a warning in 'classes/counters.php'. --- classes/counters.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'classes/counters.php') diff --git a/classes/counters.php b/classes/counters.php index 1375a6694..50d103a5c 100644 --- a/classes/counters.php +++ b/classes/counters.php @@ -273,6 +273,10 @@ class Counters { if (is_array($feeds)) { foreach ($feeds as $feed) { + if (!method_exists($feed['sender'], 'get_unread')) { + continue; + } + $cv = [ "id" => PluginHost::pfeed_to_feed_id($feed['id']), "counter" => $feed['sender']->get_unread($feed['id']) -- cgit v1.2.3-54-g00ecf From 676c5787e7aba2eac58b897fa20493dfb3b6e218 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Nov 2021 07:11:29 +0300 Subject: require virtual feed plugins to implement IVirtualFeed --- classes/counters.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'classes/counters.php') diff --git a/classes/counters.php b/classes/counters.php index 50d103a5c..c8bafa5ab 100644 --- a/classes/counters.php +++ b/classes/counters.php @@ -273,9 +273,8 @@ class Counters { if (is_array($feeds)) { foreach ($feeds as $feed) { - if (!method_exists($feed['sender'], 'get_unread')) { + if (!implements_interface($feed['sender'], 'IVirtualFeed')) continue; - } $cv = [ "id" => PluginHost::pfeed_to_feed_id($feed['id']), -- cgit v1.2.3-54-g00ecf From 2493c9cddd1d1ddff130041f9f2f229341d9545b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Nov 2021 08:19:44 +0300 Subject: set better matching type hint on virtual feed object --- classes/counters.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'classes/counters.php') diff --git a/classes/counters.php b/classes/counters.php index c8bafa5ab..c42e938f8 100644 --- a/classes/counters.php +++ b/classes/counters.php @@ -273,6 +273,8 @@ class Counters { if (is_array($feeds)) { foreach ($feeds as $feed) { + /** @var IVirtualFeed $feed['sender'] */ + if (!implements_interface($feed['sender'], 'IVirtualFeed')) continue; -- cgit v1.2.3-54-g00ecf