From c09cca75b50d94b2d0d14f43b1136527364573d0 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Sat, 6 Aug 2022 14:07:36 +0200 Subject: Fix deprecations add phpstan deprecation rules Co-authored-by: Sean Molenaar Signed-off-by: Benjamin Brahmer --- lib/Db/Item.php | 19 +++++++++++-------- lib/Fetcher/FeedFetcher.php | 9 +++++++-- lib/Utility/OPMLExporter.php | 20 +++++++++++++++----- 3 files changed, 33 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/Db/Item.php b/lib/Db/Item.php index 0ed9e9113..17bf4a048 100644 --- a/lib/Db/Item.php +++ b/lib/Db/Item.php @@ -170,10 +170,9 @@ class Item extends Entity implements IAPI, \JsonSerializable ? implode('', $this->getCategories()) : ''; + $stripedBody = ""; if (!is_null($this->getBody())) { $stripedBody = strip_tags($this->getBody()); - } else { - $stripedBody = ""; } $input_list = array($stripedBody, $this->getAuthor(), $this->getTitle(), $categoriesString); @@ -181,17 +180,14 @@ class Item extends Entity implements IAPI, \JsonSerializable $search_string = ""; foreach ($input_list as $value) { - if (is_null($value)) { - $search_string .= ""; - } else { + if (!is_null($value)) { $search_string .= html_entity_decode($value); } } $search_string .= $this->getUrl(); - $search_string .= 'UTF-8'; - $this->setSearchIndex(mb_strtolower($search_string)); + $this->setSearchIndex(mb_strtolower($search_string, 'UTF-8')); $this->setFingerprint($this->computeFingerprint()); $this->setContentHash($this->computeContentHash()); } @@ -358,6 +354,9 @@ class Item extends Entity implements IAPI, \JsonSerializable */ public function getCategories(): ?array { + if (is_null($this->getCategoriesJson())) { + return null; + } return json_decode($this->getCategoriesJson()); } @@ -606,6 +605,10 @@ class Item extends Entity implements IAPI, \JsonSerializable public function setUrl(string $url = null): self { + if (is_null($url)) { + return $this; + } + $url = trim($url); if ((strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0) && $this->url !== $url @@ -613,7 +616,7 @@ class Item extends Entity implements IAPI, \JsonSerializable $this->url = $url; $this->markFieldUpdated('url'); } - + return $this; } diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php index 209722c97..86e0edd18 100755 --- a/lib/Fetcher/FeedFetcher.php +++ b/lib/Fetcher/FeedFetcher.php @@ -354,9 +354,14 @@ class FeedFetcher implements IFeedFetcher */ protected function getFavicon(FeedInterface $feed, string $url) { + $favicon = null; // trim the string because authors do funny things - $favicon = trim($feed->getLogo()); - + $feed_logo = $feed->getLogo(); + + if (!is_null($feed_logo)) { + $favicon = trim($feed_logo); + } + ini_set('user_agent', 'NextCloud-News/1.0'); $base_url = new Net_URL2($url); diff --git a/lib/Utility/OPMLExporter.php b/lib/Utility/OPMLExporter.php index aa06f5dbf..bb813daf8 100644 --- a/lib/Utility/OPMLExporter.php +++ b/lib/Utility/OPMLExporter.php @@ -90,11 +90,21 @@ class OPMLExporter protected function createFeedOutline(Feed $feed, DOMDocument $document) { $feedOutline = $document->createElement('outline'); - $feedOutline->setAttribute('title', $feed->getTitle()); - $feedOutline->setAttribute('text', $feed->getTitle()); - $feedOutline->setAttribute('type', 'rss'); - $feedOutline->setAttribute('xmlUrl', $feed->getUrl()); - $feedOutline->setAttribute('htmlUrl', $feed->getLink()); + $attributes = [ + ['title', $feed->getTitle()], + ['text', $feed->getTitle()], + ['type', 'rss'], + ['xmlUrl', $feed->getUrl()], + ['htmlUrl', $feed->getLink()], + ]; + + foreach ($attributes as $attribute) { + if (is_null($attribute[1])) { + $feedOutline->setAttribute($attribute[0], ""); + } else { + $feedOutline->setAttribute($attribute[0], $attribute[1]); + } + } return $feedOutline; } -- cgit v1.2.3