refactor: drop usage of Debug::log (#4202)

* refactor: drop usage of Debug::log

* lint
This commit is contained in:
Dag 2024-08-08 04:31:47 +02:00 committed by GitHub
parent 6afd13eb06
commit 2acd415475
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 37 additions and 105 deletions

View file

@ -45,7 +45,6 @@ class AsahiShimbunAJWBridge extends BridgeAbstract
foreach ($html->find('#MainInner li a') as $element) { foreach ($html->find('#MainInner li a') as $element) {
if ($element->parent()->class == 'HeadlineTopImage-S') { if ($element->parent()->class == 'HeadlineTopImage-S') {
Debug::log('Skip Headline, it is repeated below');
continue; continue;
} }
$item = []; $item = [];

View file

@ -27,11 +27,6 @@ class DagensNyheterDirektBridge extends BridgeAbstract
$url = self::BASEURL . $link; $url = self::BASEURL . $link;
$title = $element->find('h2', 0)->plaintext; $title = $element->find('h2', 0)->plaintext;
$author = $element->find('div.ds-byline__titles', 0)->plaintext; $author = $element->find('div.ds-byline__titles', 0)->plaintext;
// Debug::log($link);
// Debug::log($datetime);
// Debug::log($title);
// Debug::log($url);
// Debug::log($author);
$article_content = $element->find('div.direkt-post__content', 0); $article_content = $element->find('div.direkt-post__content', 0);
$article_html = ''; $article_html = '';

View file

@ -187,7 +187,6 @@ class FicbookBridge extends BridgeAbstract
$fixed_date = str_replace(' г.', '', $fixed_date); $fixed_date = str_replace(' г.', '', $fixed_date);
if ($fixed_date === $date) { if ($fixed_date === $date) {
Debug::log('Unable to fix date: ' . $date);
return null; return null;
} }

View file

@ -44,8 +44,6 @@ class FolhaDeSaoPauloBridge extends FeedExpander
$item['content'] = $text; $item['content'] = $text;
$item['uri'] = explode('*', $item['uri'])[1]; $item['uri'] = explode('*', $item['uri'])[1];
} }
} else {
Debug::log('???: ' . $item['uri']);
} }
} else { } else {
$item['uri'] = explode('*', $item['uri'])[1]; $item['uri'] = explode('*', $item['uri'])[1];
@ -58,13 +56,11 @@ class FolhaDeSaoPauloBridge extends FeedExpander
{ {
$feed_input = $this->getInput('feed'); $feed_input = $this->getInput('feed');
if (substr($feed_input, 0, strlen(self::URI)) === self::URI) { if (substr($feed_input, 0, strlen(self::URI)) === self::URI) {
Debug::log('Input:: ' . $feed_input);
$feed_url = $feed_input; $feed_url = $feed_input;
} else { } else {
/* TODO: prepend `/` if missing */ /* TODO: prepend `/` if missing */
$feed_url = self::URI . '/' . $this->getInput('feed'); $feed_url = self::URI . '/' . $this->getInput('feed');
} }
Debug::log('URL: ' . $feed_url);
$limit = $this->getInput('amount'); $limit = $this->getInput('amount');
$this->collectExpandableDatas($feed_url, $limit); $this->collectExpandableDatas($feed_url, $limit);
} }

View file

@ -21,8 +21,6 @@ class HackerNewsUserThreadsBridge extends BridgeAbstract
{ {
$url = 'https://news.ycombinator.com/threads?id=' . $this->getInput('user'); $url = 'https://news.ycombinator.com/threads?id=' . $this->getInput('user');
$html = getSimpleHTMLDOM($url); $html = getSimpleHTMLDOM($url);
Debug::log('queried ' . $url);
Debug::log('found ' . $html);
$item = []; $item = [];
$articles = $html->find('tr[class*="comtr"]'); $articles = $html->find('tr[class*="comtr"]');

View file

@ -522,7 +522,7 @@ class ItakuBridge extends BridgeAbstract
{ {
$url = self::URI . '/api/commissions/' . $id . '/?format=json'; $url = self::URI . '/api/commissions/' . $id . '/?format=json';
$uri = self::URI . '/commissions/' . $id; $uri = self::URI . '/commissions/' . $id;
// Debug::log(var_dump($metadata));
$data = $metadata ?? $this->getData($url, true, true) $data = $metadata ?? $this->getData($url, true, true)
or returnServerError("Could not load $url"); or returnServerError("Could not load $url");
@ -664,7 +664,6 @@ class ItakuBridge extends BridgeAbstract
private function getData(string $url, bool $cache = false, bool $getJSON = false, array $httpHeaders = [], array $curlOptions = []) private function getData(string $url, bool $cache = false, bool $getJSON = false, array $httpHeaders = [], array $curlOptions = [])
{ {
// Debug::log($url);
if ($getJSON) { //get JSON object if ($getJSON) { //get JSON object
if ($cache) { if ($cache) {
$data = $this->loadCacheValue($url); $data = $this->loadCacheValue($url);

View file

@ -138,8 +138,6 @@ class JustETFBridge extends BridgeAbstract
date_time_set($df, 0, 0); date_time_set($df, 0, 0);
// Debug::log(date_format($df, 'U'));
return date_format($df, 'U'); return date_format($df, 'U');
} }
@ -216,8 +214,6 @@ class JustETFBridge extends BridgeAbstract
$element = $article->find('div.subheadline', 0) $element = $article->find('div.subheadline', 0)
or returnServerError('Date not found!'); or returnServerError('Date not found!');
// Debug::log($element->plaintext);
$date = trim(explode('|', $element->plaintext)[0]); $date = trim(explode('|', $element->plaintext)[0]);
return $this->fixDate($date); return $this->fixDate($date);
@ -230,8 +226,6 @@ class JustETFBridge extends BridgeAbstract
$element->find('a', 0)->onclick = ''; $element->find('a', 0)->onclick = '';
// Debug::log($element->innertext);
return $element->innertext; return $element->innertext;
} }
@ -300,8 +294,6 @@ class JustETFBridge extends BridgeAbstract
$element = $html->find('div.infobox div.vallabel', 0) $element = $html->find('div.infobox div.vallabel', 0)
or returnServerError('Date not found!'); or returnServerError('Date not found!');
// Debug::log($element->plaintext);
$date = trim(explode("\r\n", $element->plaintext)[1]); $date = trim(explode("\r\n", $element->plaintext)[1]);
return $this->fixDate($date); return $this->fixDate($date);

View file

@ -275,11 +275,13 @@ class MastodonBridge extends BridgeAbstract
$toSign = '(request-target): get ' . $matches[2] . "\nhost: " . $matches[1] . "\ndate: " . $date; $toSign = '(request-target): get ' . $matches[2] . "\nhost: " . $matches[1] . "\ndate: " . $date;
$result = openssl_sign($toSign, $signature, $pkey, 'RSA-SHA256'); $result = openssl_sign($toSign, $signature, $pkey, 'RSA-SHA256');
if ($result) { if ($result) {
Debug::log($toSign); $sig = sprintf(
$sig = 'Signature: keyId="' . $keyId . '",headers="(request-target) host date",signature="' . 'Signature: keyId="%s",headers="(request-target) host date",signature="%s"',
base64_encode($signature) . '"'; $keyId,
Debug::log($sig); base64_encode($signature)
array_push($headers, $sig); );
$headers[] = $sig;
} }
} }
try { try {

View file

@ -38,7 +38,7 @@ class PanacheDigitalGamesBridge extends BridgeAbstract
$image_html = $element->find('.news-item-thumbnail-image', 0); $image_html = $element->find('.news-item-thumbnail-image', 0);
if ($image_html) { if ($image_html) {
$image_strings = explode('\'', $image_html); $image_strings = explode('\'', $image_html);
/* Debug::log('S: ' . count($image_strings) . '||' . implode('_ _', $image_strings)); */
if (count($image_strings) == 4) { if (count($image_strings) == 4) {
$item['content'] = '<img src="' . $image_strings[1] . '" />'; $item['content'] = '<img src="' . $image_strings[1] . '" />';
} }

View file

@ -55,7 +55,6 @@ class PresidenciaPTBridge extends BridgeAbstract
$contexts = $this->getParameters(); $contexts = $this->getParameters();
foreach (array_keys($contexts['Section']) as $k) { foreach (array_keys($contexts['Section']) as $k) {
Debug::log('Key: ' . var_export($k, true));
if ($this->getInput($k)) { if ($this->getInput($k)) {
$html = getSimpleHTMLDOMCached($this->getURI() . $k); $html = getSimpleHTMLDOMCached($this->getURI() . $k);

View file

@ -118,13 +118,8 @@ class SlusheBridge extends BridgeAbstract
$html = getSimpleHTMLDOM($uri, $headers); $html = getSimpleHTMLDOM($uri, $headers);
//Debug::log($html);
//Debug::log($html->find('div.blog-item')[0]);
//Loop on each entry //Loop on each entry
foreach ($html->find('div.blog-item') as $element) { foreach ($html->find('div.blog-item') as $element) {
//Debug::log($element);
$title = $element->find('h3.title', 0)->first_child()->innertext; $title = $element->find('h3.title', 0)->first_child()->innertext;
$article_uri = $element->find('h3.title', 0)->first_child()->href; $article_uri = $element->find('h3.title', 0)->first_child()->href;
$timestamp = $element->find('div.publication-date', 0)->innertext; $timestamp = $element->find('div.publication-date', 0)->innertext;
@ -153,7 +148,6 @@ class SlusheBridge extends BridgeAbstract
// Add image thumbnail(s) // Add image thumbnail(s)
foreach ($media_uris->find('img') as $media_uri) { foreach ($media_uris->find('img') as $media_uri) {
$media_html .= '<a href="' . $article_uri . '">' . $media_uri . '</a>'; $media_html .= '<a href="' . $article_uri . '">' . $media_uri . '</a>';
//Debug::log('Adding to enclosures: ' . str_replace(' ', '%20', $media_uri->src));
$item['enclosures'][] = str_replace(' ', '%20', $media_uri->src); $item['enclosures'][] = str_replace(' ', '%20', $media_uri->src);
} }
} }
@ -165,7 +159,7 @@ class SlusheBridge extends BridgeAbstract
foreach ($media_uris->find('img') as $media_uri) { foreach ($media_uris->find('img') as $media_uri) {
$media_html .= '<p>Video:</p><a href="' . $media_html .= '<p>Video:</p><a href="' .
$article_uri . '">' . $media_uri . '</a>'; $article_uri . '">' . $media_uri . '</a>';
//Debug::log('Adding to enclosures: ' . $media_uri->src);
$item['enclosures'][] = $media_uri->src; $item['enclosures'][] = $media_uri->src;
} }
} }

View file

@ -70,9 +70,9 @@ class ThreadsBridge extends BridgeAbstract
public function collectData() public function collectData()
{ {
$html = getSimpleHTMLDOMCached($this->getURI(), static::CACHE_TIMEOUT); $html = getSimpleHTMLDOMCached($this->getURI(), static::CACHE_TIMEOUT);
Debug::log(sprintf('Fetched: %s', $this->getURI()));
$jsonBlobs = $html->find('script[type="application/json"]'); $jsonBlobs = $html->find('script[type="application/json"]');
Debug::log(sprintf('%d JSON blobs found.', count($jsonBlobs)));
$gatheredCodes = []; $gatheredCodes = [];
$limit = $this->getInput('limit'); $limit = $this->getInput('limit');
foreach ($jsonBlobs as $jsonBlob) { foreach ($jsonBlobs as $jsonBlob) {
@ -87,7 +87,6 @@ class ThreadsBridge extends BridgeAbstract
} }
} }
} }
Debug::log(sprintf('Candidate codes found in JSON in script tags: %s', print_r($gatheredCodes, true)));
$this->feedName = html_entity_decode($html->find('meta[property=og:title]', 0)->content); $this->feedName = html_entity_decode($html->find('meta[property=og:title]', 0)->content);
// todo: meta[property=og:description] could populate the feed description // todo: meta[property=og:description] could populate the feed description

View file

@ -541,7 +541,7 @@ EOD;
} }
break; break;
default: default:
Debug::log('Missing support for media type: ' . $media->type); break;
} }
} }
} }

View file

@ -192,7 +192,6 @@ EOD
. $this->getInput('u'), $authHeaders, $params); . $this->getInput('u'), $authHeaders, $params);
if (isset($user->errors)) { if (isset($user->errors)) {
Debug::log('User JSON: ' . json_encode($user));
returnServerError('Requested username can\'t be found.'); returnServerError('Requested username can\'t be found.');
} }
@ -266,7 +265,6 @@ EOD
(isset($data->errors) && !isset($data->data)) || (isset($data->errors) && !isset($data->data)) ||
(isset($data->meta) && $data->meta->result_count === 0) (isset($data->meta) && $data->meta->result_count === 0)
) { ) {
Debug::log('Data JSON: ' . json_encode($data));
switch ($this->queriedContext) { switch ($this->queriedContext) {
case 'By keyword or hashtag': case 'By keyword or hashtag':
returnServerError('No results for this query.'); returnServerError('No results for this query.');
@ -311,7 +309,6 @@ EOD
foreach ($includesTweets as $includesTweet) { foreach ($includesTweets as $includesTweet) {
$includesTweetsIds[] = $includesTweet->id; $includesTweetsIds[] = $includesTweet->id;
} }
Debug::log('includesTweetsIds: ' . join(',', $includesTweetsIds));
// Set default params for API query // Set default params for API query
$params = [ $params = [
@ -336,8 +333,6 @@ EOD
// Create output array with all required elements for each tweet // Create output array with all required elements for each tweet
foreach ($tweets as $tweet) { foreach ($tweets as $tweet) {
//Debug::log('Tweet JSON: ' . json_encode($tweet));
// Skip pinned tweet (if selected) // Skip pinned tweet (if selected)
if ($hidePinned && $tweet->id === $pinnedTweetId) { if ($hidePinned && $tweet->id === $pinnedTweetId) {
continue; continue;
@ -376,12 +371,10 @@ EOD
$cleanedQuotedTweet = null; $cleanedQuotedTweet = null;
$quotedUser = null; $quotedUser = null;
if ($isQuote) { if ($isQuote) {
Debug::log('Tweet is quote');
foreach ($includesTweets as $includesTweet) { foreach ($includesTweets as $includesTweet) {
if ($includesTweet->id === $tweet->referenced_tweets[0]->id) { if ($includesTweet->id === $tweet->referenced_tweets[0]->id) {
$quotedTweet = $includesTweet; $quotedTweet = $includesTweet;
$cleanedQuotedTweet = nl2br($quotedTweet->text); $cleanedQuotedTweet = nl2br($quotedTweet->text);
//Debug::log('Found quoted tweet');
break; break;
} }
} }
@ -389,7 +382,6 @@ EOD
$quotedUser = $this->getTweetUser($quotedTweet, $retweetedUsers, $includesUsers); $quotedUser = $this->getTweetUser($quotedTweet, $retweetedUsers, $includesUsers);
} }
if ($isRetweet || is_null($user)) { if ($isRetweet || is_null($user)) {
Debug::log('Tweet is retweet, or $user is null');
// Replace tweet object with original retweeted object // Replace tweet object with original retweeted object
if ($isRetweet) { if ($isRetweet) {
foreach ($includesTweets as $includesTweet) { foreach ($includesTweets as $includesTweet) {
@ -430,7 +422,6 @@ EOD
. $this->item['username'] . ')'; . $this->item['username'] . ')';
$cleanedTweet = nl2br($tweet->text); $cleanedTweet = nl2br($tweet->text);
//Debug::log('cleanedTweet: ' . $cleanedTweet);
// Perform optional keyword filtering (only keep tweet if keyword is found) // Perform optional keyword filtering (only keep tweet if keyword is found)
if (! empty($tweetFilter)) { if (! empty($tweetFilter)) {
@ -452,7 +443,6 @@ EOD
// Search for and replace URLs in Tweet text // Search for and replace URLs in Tweet text
$cleanedTweet = $this->replaceTweetURLs($tweet, $cleanedTweet); $cleanedTweet = $this->replaceTweetURLs($tweet, $cleanedTweet);
if (isset($cleanedQuotedTweet)) { if (isset($cleanedQuotedTweet)) {
Debug::log('Replacing URLs in Quoted Tweet text');
$cleanedQuotedTweet = $this->replaceTweetURLs($quotedTweet, $cleanedQuotedTweet); $cleanedQuotedTweet = $this->replaceTweetURLs($quotedTweet, $cleanedQuotedTweet);
} }
@ -478,9 +468,7 @@ EOD
// Get external link info // Get external link info
$extURL = null; $extURL = null;
if (isset($tweet->entities->urls) && strpos($tweet->entities->urls[0]->expanded_url, 'twitter.com') === false) { if (isset($tweet->entities->urls) && strpos($tweet->entities->urls[0]->expanded_url, 'twitter.com') === false) {
Debug::log('Found an external link!');
$extURL = $tweet->entities->urls[0]->expanded_url; $extURL = $tweet->entities->urls[0]->expanded_url;
Debug::log($extURL);
$extDisplayURL = $tweet->entities->urls[0]->display_url; $extDisplayURL = $tweet->entities->urls[0]->display_url;
$extTitle = $tweet->entities->urls[0]->title; $extTitle = $tweet->entities->urls[0]->title;
$extDesc = $tweet->entities->urls[0]->description; $extDesc = $tweet->entities->urls[0]->description;
@ -513,15 +501,12 @@ EOD;
$ext_media_html = ''; $ext_media_html = '';
if (!$hideImages) { if (!$hideImages) {
if (isset($tweet->attachments->media_keys)) { if (isset($tweet->attachments->media_keys)) {
Debug::log('Generating HTML for tweet media');
$media_html = $this->createTweetMediaHTML($tweet, $includesMedia, $retweetedMedia); $media_html = $this->createTweetMediaHTML($tweet, $includesMedia, $retweetedMedia);
} }
if (isset($quotedTweet->attachments->media_keys)) { if (isset($quotedTweet->attachments->media_keys)) {
Debug::log('Generating HTML for quoted tweet media');
$quoted_media_html = $this->createTweetMediaHTML($quotedTweet, $includesMedia, $retweetedMedia); $quoted_media_html = $this->createTweetMediaHTML($quotedTweet, $includesMedia, $retweetedMedia);
} }
if (isset($extURL)) { if (isset($extURL)) {
Debug::log('Generating HTML for external link media');
if ($this->getInput('noimgscaling')) { if ($this->getInput('noimgscaling')) {
$extMediaURL = $extMediaOrig; $extMediaURL = $extMediaOrig;
} else { } else {
@ -562,7 +547,6 @@ QUOTE;
// Add External Link HTML, if relevant // Add External Link HTML, if relevant
if (isset($extURL) && !$this->getInput('noexternallink')) { if (isset($extURL) && !$this->getInput('noexternallink')) {
Debug::log('Adding HTML for external link');
$ext_html = <<<EXTERNAL $ext_html = <<<EXTERNAL
<div style="display: table; border-style: solid; border-width: 1px; border-radius: 5px; padding: 5px;"> <div style="display: table; border-style: solid; border-width: 1px; border-radius: 5px; padding: 5px;">
$ext_media_html<br> $ext_media_html<br>
@ -653,21 +637,18 @@ EXTERNAL;
{ {
$originalUser = new stdClass(); // make the linters stop complaining $originalUser = new stdClass(); // make the linters stop complaining
if (isset($retweetedUsers)) { if (isset($retweetedUsers)) {
Debug::log('Searching for tweet author_id in $retweetedUsers');
foreach ($retweetedUsers as $retweetedUser) { foreach ($retweetedUsers as $retweetedUser) {
if ($retweetedUser->id === $tweetObject->author_id) { if ($retweetedUser->id === $tweetObject->author_id) {
$matchedUser = $retweetedUser; $matchedUser = $retweetedUser;
Debug::log('Found author_id match in $retweetedUsers');
break; break;
} }
} }
} }
if (!isset($matchedUser->username) && isset($includesUsers)) { if (!isset($matchedUser->username) && isset($includesUsers)) {
Debug::log('Searching for tweet author_id in $includesUsers');
foreach ($includesUsers as $includesUser) { foreach ($includesUsers as $includesUser) {
if ($includesUser->id === $tweetObject->author_id) { if ($includesUser->id === $tweetObject->author_id) {
$matchedUser = $includesUser; $matchedUser = $includesUser;
Debug::log('Found author_id match in $includesUsers');
break; break;
} }
} }
@ -689,7 +670,6 @@ EXTERNAL;
$tweetMedia = []; $tweetMedia = [];
// Start by checking the original list of tweet Media includes // Start by checking the original list of tweet Media includes
if (isset($includesMedia)) { if (isset($includesMedia)) {
Debug::log('Searching for media_key in $includesMedia');
foreach ($includesMedia as $includesMedium) { foreach ($includesMedia as $includesMedium) {
if ( if (
in_array( in_array(
@ -697,14 +677,12 @@ EXTERNAL;
$tweetObject->attachments->media_keys $tweetObject->attachments->media_keys
) )
) { ) {
Debug::log('Found media_key in $includesMedia');
$tweetMedia[] = $includesMedium; $tweetMedia[] = $includesMedium;
} }
} }
} }
// If no matches found, check the retweet Media includes // If no matches found, check the retweet Media includes
if (empty($tweetMedia) && isset($retweetedMedia)) { if (empty($tweetMedia) && isset($retweetedMedia)) {
Debug::log('Searching for media_key in $retweetedMedia');
foreach ($retweetedMedia as $retweetedMedium) { foreach ($retweetedMedia as $retweetedMedium) {
if ( if (
in_array( in_array(
@ -712,7 +690,6 @@ EXTERNAL;
$tweetObject->attachments->media_keys $tweetObject->attachments->media_keys
) )
) { ) {
Debug::log('Found media_key in $retweetedMedia');
$tweetMedia[] = $retweetedMedium; $tweetMedia[] = $retweetedMedium;
} }
} }
@ -760,8 +737,7 @@ EOD;
EOD; EOD;
break; break;
default: default:
Debug::log('Missing support for media type: ' break;
. $media->type);
} }
} }

View file

@ -14,14 +14,12 @@ class UnraidCommunityApplicationsBridge extends BridgeAbstract
private function fetchApps() private function fetchApps()
{ {
Debug::log('Fetching all applications/plugins');
$this->apps = getContents(self::APPSURI); $this->apps = getContents(self::APPSURI);
$this->apps = json_decode($this->apps, true)['applist']; $this->apps = json_decode($this->apps, true)['applist'];
} }
private function sortApps() private function sortApps()
{ {
Debug::log('Sorting applications/plugins');
usort($this->apps, function ($app1, $app2) { usort($this->apps, function ($app1, $app2) {
return $app1['FirstSeen'] < $app2['FirstSeen'] ? 1 : -1; return $app1['FirstSeen'] < $app2['FirstSeen'] ? 1 : -1;
}); });

View file

@ -436,8 +436,6 @@ class XenForoBridge extends BridgeAbstract
break; break;
} }
// Debug::log(date_format($df, 'U'));
return date_format($df, 'U'); return date_format($df, 'U');
} }
} }

View file

@ -192,7 +192,7 @@ final class BridgeCard
{ {
$required = $entry['required'] ?? null; $required = $entry['required'] ?? null;
if ($required) { if ($required) {
Debug::log('The "required" attribute is not supported for lists.'); trigger_error('The required attribute is not supported for lists');
unset($entry['required']); unset($entry['required']);
} }
@ -235,7 +235,7 @@ final class BridgeCard
{ {
$required = $entry['required'] ?? null; $required = $entry['required'] ?? null;
if ($required) { if ($required) {
Debug::log('The "required" attribute is not supported for checkboxes.'); trigger_error('The required attribute is not supported for checkboxes');
unset($entry['required']); unset($entry['required']);
} }

View file

@ -15,20 +15,4 @@ class Debug
} }
return false; return false;
} }
/**
* @deprecated Use $this->logger->debug()
*/
public static function log($message)
{
$e = new \Exception();
$trace = trace_from_exception($e);
// Drop the current frame
array_pop($trace);
$lastFrame = $trace[array_key_last($trace)];
$text = sprintf('%s(%s): %s', $lastFrame['file'], $lastFrame['line'], $message);
$logger = RssBridge::getLogger();
$logger->debug($text);
}
} }

View file

@ -12,6 +12,8 @@ class FeedItem
protected ?string $uid = null; protected ?string $uid = null;
protected array $misc = []; protected array $misc = [];
private Logger $logger;
public static function fromArray(array $itemArray): self public static function fromArray(array $itemArray): self
{ {
$item = new self(); $item = new self();
@ -23,6 +25,7 @@ class FeedItem
private function __construct() private function __construct()
{ {
$this->logger = RssBridge::getLogger();
} }
public function __set($name, $value) public function __set($name, $value)
@ -99,17 +102,17 @@ class FeedItem
} elseif ($uri->hasAttribute('src')) { // Image } elseif ($uri->hasAttribute('src')) { // Image
$uri = $uri->src; $uri = $uri->src;
} else { } else {
Debug::log('The item provided as URI is unknown!'); $this->logger->debug('The item provided as URI is unknown!');
} }
} }
if (!is_string($uri)) { if (!is_string($uri)) {
Debug::log(sprintf('Expected $uri to be string but got %s', gettype($uri))); $this->logger->debug(sprintf('Expected $uri to be string but got %s', gettype($uri)));
return; return;
} }
$uri = trim($uri); $uri = trim($uri);
// Intentionally doing a weak url validation here because FILTER_VALIDATE_URL is too strict // Intentionally doing a weak url validation here because FILTER_VALIDATE_URL is too strict
if (!preg_match('#^https?://#i', $uri)) { if (!preg_match('#^https?://#i', $uri)) {
Debug::log(sprintf('Not a valid url: "%s"', $uri)); $this->logger->debug(sprintf('Not a valid url: "%s"', $uri));
return; return;
} }
$this->uri = $uri; $this->uri = $uri;
@ -124,7 +127,7 @@ class FeedItem
{ {
$this->title = null; $this->title = null;
if (!is_string($title)) { if (!is_string($title)) {
trigger_error('Title must be a string: ' . print_r($title, true)); $this->logger->debug('Title must be a string: ' . print_r($title, true));
} else { } else {
$this->title = truncate(trim($title)); $this->title = truncate(trim($title));
} }
@ -143,11 +146,11 @@ class FeedItem
} else { } else {
$timestamp = strtotime($datetime); $timestamp = strtotime($datetime);
if ($timestamp === false) { if ($timestamp === false) {
Debug::log('Unable to parse timestamp!'); $this->logger->debug('Unable to parse timestamp!');
} }
} }
if ($timestamp <= 0) { if ($timestamp <= 0) {
Debug::log('Timestamp must be greater than zero!'); $this->logger->debug('Timestamp must be greater than zero!');
} else { } else {
$this->timestamp = $timestamp; $this->timestamp = $timestamp;
} }
@ -162,7 +165,7 @@ class FeedItem
{ {
$this->author = null; $this->author = null;
if (!is_string($author)) { if (!is_string($author)) {
Debug::log('Author must be a string!'); $this->logger->debug('Author must be a string!');
} else { } else {
$this->author = $author; $this->author = $author;
} }
@ -190,7 +193,7 @@ class FeedItem
if (is_string($content)) { if (is_string($content)) {
$this->content = $content; $this->content = $content;
} else { } else {
Debug::log(sprintf('Unable to convert feed content to string: %s', gettype($content))); $this->logger->debug(sprintf('Unable to convert feed content to string: %s', gettype($content)));
} }
} }
@ -204,7 +207,7 @@ class FeedItem
$this->enclosures = []; $this->enclosures = [];
if (!is_array($enclosures)) { if (!is_array($enclosures)) {
Debug::log('Enclosures must be an array!'); $this->logger->debug('Enclosures must be an array!');
return; return;
} }
foreach ($enclosures as $enclosure) { foreach ($enclosures as $enclosure) {
@ -215,7 +218,7 @@ class FeedItem
FILTER_FLAG_PATH_REQUIRED FILTER_FLAG_PATH_REQUIRED
) )
) { ) {
Debug::log('Each enclosure must contain a scheme, host and path!'); $this->logger->debug('Each enclosure must contain a scheme, host and path!');
} elseif (!in_array($enclosure, $this->enclosures)) { } elseif (!in_array($enclosure, $this->enclosures)) {
$this->enclosures[] = $enclosure; $this->enclosures[] = $enclosure;
} }
@ -232,14 +235,14 @@ class FeedItem
$this->categories = []; $this->categories = [];
if (!is_array($categories)) { if (!is_array($categories)) {
Debug::log('Categories must be an array!'); $this->logger->debug('Categories must be an array!');
return; return;
} }
foreach ($categories as $category) { foreach ($categories as $category) {
if (is_string($category)) { if (is_string($category)) {
$this->categories[] = $category; $this->categories[] = $category;
} else { } else {
Debug::log('Category must be a string!'); $this->logger->debug('Category must be a string!');
} }
} }
} }
@ -253,7 +256,7 @@ class FeedItem
{ {
$this->uid = null; $this->uid = null;
if (!is_string($uid)) { if (!is_string($uid)) {
Debug::log(sprintf('uid must be string: %s (%s)', (string) $uid, var_export($uid, true))); $this->logger->debug(sprintf('uid must be string: %s (%s)', (string) $uid, var_export($uid, true)));
return; return;
} }
if (preg_match('/^[a-f0-9]{40}$/', $uid)) { if (preg_match('/^[a-f0-9]{40}$/', $uid)) {
@ -267,9 +270,9 @@ class FeedItem
public function addMisc($name, $value) public function addMisc($name, $value)
{ {
if (!is_string($name)) { if (!is_string($name)) {
Debug::log('Key must be a string!'); $this->logger->debug('Key must be a string!');
} elseif (in_array($name, get_object_vars($this))) { } elseif (in_array($name, get_object_vars($this))) {
Debug::log('Key must be unique!'); $this->logger->debug('Key must be unique!');
} else { } else {
$this->misc[$name] = $value; $this->misc[$name] = $value;
} }

View file

@ -100,7 +100,8 @@ final class RssBridge
public static function getLogger(): Logger public static function getLogger(): Logger
{ {
return self::$logger; // null logger is only for the tests not to fail
return self::$logger ?? new NullLogger();
} }
public static function getCache(): CacheInterface public static function getCache(): CacheInterface