diff --git a/application/forms/ConfigForm.php b/application/forms/ConfigForm.php index aa67ff1..6d4d2dc 100644 --- a/application/forms/ConfigForm.php +++ b/application/forms/ConfigForm.php @@ -11,7 +11,7 @@ public function init() $this->setSubmitLabel(t('Save Changes')); } - public function createElements(array $formData) + public function createElements(array $formData): void { $this->addElement('number', 'http_timeout', [ 'label' => t('Timeout for HTTP calls in seconds'), diff --git a/application/forms/FeedForm.php b/application/forms/FeedForm.php index 437923a..965953d 100644 --- a/application/forms/FeedForm.php +++ b/application/forms/FeedForm.php @@ -141,7 +141,7 @@ protected function assemble(): void } } - public function isValid() + public function isValid(): bool { if ($this->getPressedSubmitElement()->getName() === 'delete') { $csrfElement = $this->getElement('CSRFToken'); @@ -175,7 +175,7 @@ public function hasDeleteButton(): bool return $this->deleteButtonName !== null; } - public function shouldBeDeleted() + public function shouldBeDeleted(): bool { if (!$this->hasDeleteButton()) { return false; diff --git a/library/Feeds/Parser/JsonfeedParser.php b/library/Feeds/Parser/JsonfeedParser.php index 254fac7..c474df7 100644 --- a/library/Feeds/Parser/JsonfeedParser.php +++ b/library/Feeds/Parser/JsonfeedParser.php @@ -19,7 +19,7 @@ class JsonfeedParser */ public static function parse(string $raw): Feed { - $json = json_decode($raw, true); + $json = json_decode($raw, true, 512, JSON_THROW_ON_ERROR); if ($json === null) { throw new Exception('Invalid JSONfeed'); } diff --git a/library/Feeds/Parser/RSSParser.php b/library/Feeds/Parser/RSSParser.php index 9fae579..ca18b1b 100644 --- a/library/Feeds/Parser/RSSParser.php +++ b/library/Feeds/Parser/RSSParser.php @@ -86,13 +86,6 @@ protected static function parseDateTime(string $dateStr): ?DateTime ); } - if ($datetime === false) { - $datetime = DateTime::createFromFormat( - DateTimeInterface::RFC7231, - $dateStr, - ); - } - if ($datetime === false) { try { $datetime = new DateTime($dateStr); diff --git a/library/Feeds/Storage/FilesystemStorage.php b/library/Feeds/Storage/FilesystemStorage.php index e400b03..d82257e 100644 --- a/library/Feeds/Storage/FilesystemStorage.php +++ b/library/Feeds/Storage/FilesystemStorage.php @@ -3,6 +3,7 @@ namespace Icinga\Module\Feeds\Storage; use Icinga\Application\Icinga; +use Icinga\Application\Logger; use Icinga\Exception\NotReadableError; use Icinga\Exception\NotWritableError; use Icinga\Exception\SystemPermissionException; @@ -67,6 +68,7 @@ protected function loadFeedFile(string $filename): FeedDefinition throw new NotReadableError('Could not read file %s', $filePath); } + // This will throw an expection, which we will catch just like the others $json = Json::decode($data, true); $feed = FeedDefinition::fromArray($json); @@ -171,7 +173,12 @@ protected function load(): void continue; } - $feed = $this->loadFeedFile($name); + try { + $feed = $this->loadFeedFile($name); + } catch (Exception $ex) { + Logger::error('Failed to load feed file "%s": %s', $name, $e); + continue; + } if ($feed->name === '') { continue;