From 7f7e896c2c27b3306004509e08320e9a13cc03e0 Mon Sep 17 00:00:00 2001 From: Bas van Dinther Date: Thu, 17 Aug 2023 15:01:02 +0200 Subject: [PATCH] Improve information --- resources/lang/en.json | 2 +- resources/lang/nl.json | 2 +- src/Checks/Content/TooLongSentenceCheck.php | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/resources/lang/en.json b/resources/lang/en.json index ad0a38f8..b659679d 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -37,7 +37,7 @@ "failed.content.no_heading": "The page does not contain any h1 tag, while it should.", "failed.content.no_title": "The page does not contain a title tag, while it should.", "failed.content.title_length": "The page title is :actualValue characters long. It should be max :expectedValue characters long.", - "failed.content.too_long_sentence": "The page contains :actualValue sentences that are too long.", + "failed.content.too_long_sentence": "The page has :actualValue too long sentences which exceeds 20% of the total sentences. Rectify :neededToFix sentences to meet the 20% limit.", "failed.content.transition_words_ratio_check.no_phrases_found": "The page does not contain any transition words.", "failed.content.transition_words_ratio_check.too_few_transition_words": "The page contains too few transition words. The recommended minimum is 30%, while the actual number is :actualValue%.", "failed.meta.description": "The page does not contain a description meta tag, while it should.", diff --git a/resources/lang/nl.json b/resources/lang/nl.json index dddcd011..40ef334c 100644 --- a/resources/lang/nl.json +++ b/resources/lang/nl.json @@ -37,7 +37,7 @@ "failed.content.no_heading": "The page does not contain any h1 tag, while it should.", "failed.content.no_title": "The page does not contain a title tag, while it should.", "failed.content.title_length": "The page title is :actualValue characters long. It should be max :expectedValue characters long.", - "failed.content.too_long_sentence": "The page contains :actualValue sentences that are too long.", + "failed.content.too_long_sentence": "De pagina bevat :actualValue te lange zinnen welke meer dan 20% van het totale aantal zinnen uitmaken. Corrigeer :neededToFix zinnen om aan de limiet van 20% te voldoen.", "failed.content.transition_words_ratio_check.no_phrases_found": "De pagina bevat geen zinnen.", "failed.content.transition_words_ratio_check.too_few_transition_words": "De pagina bevat te weinig transitiewoorden. Het zou minstens 30% moeten zijn, maar het is :actualValue%.", "failed.meta.description": "The page does not contain a description meta tag, while it should.", diff --git a/src/Checks/Content/TooLongSentenceCheck.php b/src/Checks/Content/TooLongSentenceCheck.php index 57129bfc..895e2ba9 100644 --- a/src/Checks/Content/TooLongSentenceCheck.php +++ b/src/Checks/Content/TooLongSentenceCheck.php @@ -53,8 +53,13 @@ public function validateContent(Response $response, Crawler $crawler): bool // If more than 20% of the total sentences are too long, fail if (count($sentencesWithTooManyWords) / count($phrases) > 0.2) { + + // Count how many sentences needed to fix to fall below 20% + $sentencesNeededToFix = count($sentencesWithTooManyWords) - (count($phrases) * 0.2); + $this->failureReason = __('failed.content.too_long_sentence', [ 'actualValue' => count($this->actualValue), + 'neededToFix' => round($sentencesNeededToFix, 0, PHP_ROUND_HALF_UP), ]); return false;