summaryrefslogtreecommitdiffstats
path: root/lib/Fetcher
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2019-01-31 10:23:56 +0100
committerSean Molenaar <sean@seanmolenaar.eu>2019-01-31 10:23:56 +0100
commitd61a57bd2dbbc6ecbddfaa22c347248210703f02 (patch)
treef8db17a80c431ef4029f4e25bbbb6334d8c16b96 /lib/Fetcher
parenta3246a927de542e1b3ab403359bfd3c08705b6a7 (diff)
Make feed failing more verbose
Diffstat (limited to 'lib/Fetcher')
-rw-r--r--lib/Fetcher/FeedFetcher.php34
-rw-r--r--lib/Fetcher/IFeedFetcher.php4
-rw-r--r--lib/Fetcher/YoutubeFetcher.php5
3 files changed, 17 insertions, 26 deletions
diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php
index ae338ca09..abfd0095b 100644
--- a/lib/Fetcher/FeedFetcher.php
+++ b/lib/Fetcher/FeedFetcher.php
@@ -18,7 +18,6 @@ use Favicon\Favicon;
use FeedIo\Feed\ItemInterface;
use FeedIo\FeedInterface;
use FeedIo\FeedIo;
-use OCP\Http\Client\IClientService;
use OCP\IL10N;
@@ -33,20 +32,13 @@ class FeedFetcher implements IFeedFetcher
private $reader;
private $l10n;
private $time;
- private $clientService;
-
- public function __construct(
- FeedIo $fetcher,
- Favicon $favicon,
- IL10N $l10n,
- Time $time,
- IClientService $clientService
- ) {
- $this->faviconFactory = $favicon;
+
+ public function __construct(FeedIo $fetcher, Favicon $favicon, IL10N $l10n, Time $time)
+ {
$this->reader = $fetcher;
- $this->time = $time;
+ $this->faviconFactory = $favicon;
$this->l10n = $l10n;
- $this->clientService = $clientService;
+ $this->time = $time;
}
@@ -57,7 +49,7 @@ class FeedFetcher implements IFeedFetcher
*
* @return bool
*/
- public function canHandle($url)
+ public function canHandle($url): bool
{
return true;
}
@@ -79,7 +71,7 @@ class FeedFetcher implements IFeedFetcher
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
- public function fetch($url, $getFavicon = true, $lastModified = null, $user = null, $password = null)
+ public function fetch(string $url, $getFavicon = true, $lastModified = null, $user = null, $password = null): array
{
if ($user !== null && trim($user) !== '') {
$url = explode('://', $url);
@@ -88,7 +80,7 @@ class FeedFetcher implements IFeedFetcher
$resource = $this->reader->readSince($url, new DateTime($lastModified));
if (!$resource->getResponse()->isModified()) {
- return [null, null];
+ throw new FetcherException('Feed was not modified since last fetch');
}
$location = $resource->getUrl();
@@ -115,7 +107,7 @@ class FeedFetcher implements IFeedFetcher
*
* @return string
*/
- private function decodeTwice($string)
+ private function decodeTwice($string): string
{
return html_entity_decode(
html_entity_decode(
@@ -135,7 +127,7 @@ class FeedFetcher implements IFeedFetcher
*
* @return bool
*/
- protected function determineRtl($parsedFeed)
+ protected function determineRtl(FeedInterface $parsedFeed): bool
{
$language = $parsedFeed->getLanguage();
@@ -166,7 +158,7 @@ class FeedFetcher implements IFeedFetcher
*
* @return Item
*/
- protected function buildItem($parsedItem, $parsedFeed)
+ protected function buildItem(ItemInterface $parsedItem, FeedInterface $parsedFeed): Item
{
$item = new Item();
$item->setUnread(true);
@@ -223,12 +215,12 @@ class FeedFetcher implements IFeedFetcher
*
* @param FeedInterface $feed Feed to build from
* @param string $url URL to use
- * @param bool $getFavicon To get the favicon
+ * @param boolean $getFavicon To get the favicon
* @param string $location String base URL
*
* @return Feed
*/
- protected function buildFeed($feed, $url, $getFavicon, $location)
+ protected function buildFeed(FeedInterface $feed, string $url, boolean $getFavicon, string $location): Feed
{
$newFeed = new Feed();
diff --git a/lib/Fetcher/IFeedFetcher.php b/lib/Fetcher/IFeedFetcher.php
index d5994a076..70f153d2e 100644
--- a/lib/Fetcher/IFeedFetcher.php
+++ b/lib/Fetcher/IFeedFetcher.php
@@ -30,7 +30,7 @@ interface IFeedFetcher
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
- public function fetch($url, $getFavicon = true, $lastModified = null, $user = null, $password = null);
+ public function fetch($url, $getFavicon = true, $lastModified = null, $user = null, $password = null): array;
/**
* Can a fetcher handle a feed.
@@ -40,5 +40,5 @@ interface IFeedFetcher
* @return boolean if the fetcher can handle the url. This fetcher will be
* used exclusively to fetch the feed and the items of the page
*/
- public function canHandle($url);
+ public function canHandle($url): bool;
}
diff --git a/lib/Fetcher/YoutubeFetcher.php b/lib/Fetcher/YoutubeFetcher.php
index 9ccce4463..fd4e7d2fb 100644
--- a/lib/Fetcher/YoutubeFetcher.php
+++ b/lib/Fetcher/YoutubeFetcher.php
@@ -39,7 +39,7 @@ class YoutubeFetcher implements IFeedFetcher
/**
* This fetcher handles all the remaining urls therefore always returns true
*/
- public function canHandle($url)
+ public function canHandle($url): bool
{
return $this->buildUrl($url) !== $url;
}
@@ -59,8 +59,7 @@ class YoutubeFetcher implements IFeedFetcher
* @return array an array containing the new feed and its items, first
* element being the Feed and second element being an array of Items
*/
- public function fetch($url, $getFavicon = true, $lastModified = null, $user = null, $password = null
- )
+ public function fetch($url, $getFavicon = true, $lastModified = null, $user = null, $password = null): array
{
$transformedUrl = $this->buildUrl($url);