From 0f35d9a53de38b4d484a36ac99b3362cb829e170 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Sat, 23 Jan 2021 17:49:56 +0100 Subject: [PATCH] Fixed some bugs in the code Signed-off-by: Christian Wolf --- lib/Helper/HTMLFilter/HtmlEntiryDecodeFilter.php | 2 +- lib/Helper/HTMLParser/HttpJsonLdParser.php | 2 ++ lib/Service/HtmlDownloadService.php | 16 ++++------------ lib/Service/RecipeExtractionService.php | 1 + 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/Helper/HTMLFilter/HtmlEntiryDecodeFilter.php b/lib/Helper/HTMLFilter/HtmlEntiryDecodeFilter.php index 5606d1eb..0afa3802 100644 --- a/lib/Helper/HTMLFilter/HtmlEntiryDecodeFilter.php +++ b/lib/Helper/HTMLFilter/HtmlEntiryDecodeFilter.php @@ -3,7 +3,7 @@ namespace OCA\Cookbook\Helper\HTMLFilter; class HtmlEntiryDecodeFilter extends AbstractHtmlFilter { - public function apply(string $html): void { + public function apply(string &$html): void { $html = html_entity_decode($html); } } diff --git a/lib/Helper/HTMLParser/HttpJsonLdParser.php b/lib/Helper/HTMLParser/HttpJsonLdParser.php index 971f8369..d4a08b3d 100644 --- a/lib/Helper/HTMLParser/HttpJsonLdParser.php +++ b/lib/Helper/HTMLParser/HttpJsonLdParser.php @@ -19,6 +19,8 @@ class HttpJsonLdParser extends AbstractHtmlParser { public function __construct(IL10N $l10n, JsonService $jsonService) { parent::__construct($l10n); + + $this->jsonService = $jsonService; } public function parse(\DOMDocument $document): array { diff --git a/lib/Service/HtmlDownloadService.php b/lib/Service/HtmlDownloadService.php index f2fbd6cf..caa161d3 100644 --- a/lib/Service/HtmlDownloadService.php +++ b/lib/Service/HtmlDownloadService.php @@ -199,32 +199,24 @@ class HtmlDownloadService { /** @var \LibXMLError $error */ $error = $by_error_code[$code]; - // Collect data for translations - $params = []; - $params['code'] = $error->code; - $params['count'] = $count; - $params['url'] = $url; - $params['line'] = $error->line; - $params['column'] = $error->column; - switch ($error->level) { case LIBXML_ERR_WARNING: - $error_message = $this->l->t("Warning {code} occurred {count} times while parsing {url}.", $params); + $error_message = $this->l->t('Warning %u occurred %u times while parsing %s.', [$error->code, $count, $url]); $return = max($return, self::PARSING_WARNING); break; case LIBXML_ERR_ERROR: - $error_message = $this->l->t("Error {code} occurred {count} times while parsing {url}.", $params); + $error_message = $this->l->t('Error %u occurred %u times while parsing %s.', [$error->code, $count, $url]); $return = max($return, self::PARSING_ERROR); break; case LIBXML_ERR_FATAL: - $error_message = $this->l->t("Fatal error {code} occurred {count} times while parsing {url}.", $params); + $error_message = $this->l->t('Fatal error %u occurred %count$u times while parsing %s.', [$error->code, $count, $url]); $return = max($return, self::PARSING_FATAL_ERROR); break; default: throw new \Exception($this->l->t('Unsupported error level during parsing of XML output.')); } - $last_occurence = $this->l->t('Last time it occurred in line {line} and column {column}', $params); + $last_occurence = $this->l->t('Last time it occurred in line %u and column %u', [$error->line, $error->column]); $error_message = "libxml: $error_message $last_occurence: " . $error->message; $this->logger->warning($error_message); diff --git a/lib/Service/RecipeExtractionService.php b/lib/Service/RecipeExtractionService.php index 3dfbb4fe..a38b963d 100644 --- a/lib/Service/RecipeExtractionService.php +++ b/lib/Service/RecipeExtractionService.php @@ -23,6 +23,7 @@ class RecipeExtractionService { public function __construct(HttpJsonLdParser $jsonParser, HttpMicrodataParser $microdataParser, IL10N $l10n) { $this->parsers = [$jsonParser, $microdataParser]; + $this->l = $l10n; } /**