From 8d18d9ed898e4595175a7ebb2cc3cbf638796956 Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Fri, 11 Nov 2022 15:37:04 +0100
Subject: [PATCH] [TASK] Clean up some linkvalidator classes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Minor class modification to make the code more
dense, more strict and reduce duplication.

Resolves: #99094
Releases: main
Change-Id: Iac3e7926dd16351ae0e0e7c45dfd099aa2eb61b6
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76608
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Jochen <rothjochen@gmail.com>
Reviewed-by: Jochen <rothjochen@gmail.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../linkvalidator/Classes/LinkAnalyzer.php    |  2 +-
 .../Classes/Result/LinkAnalyzerResult.php     | 76 +++----------------
 .../Classes/Task/ValidatorTask.php            | 32 +-------
 3 files changed, 15 insertions(+), 95 deletions(-)

diff --git a/typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php b/typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php
index 891fa8128a50..562430f4e4ce 100644
--- a/typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php
+++ b/typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php
@@ -449,7 +449,7 @@ class LinkAnalyzer
      *
      * @return array array with the number of links found
      */
-    public function getLinkCounts()
+    public function getLinkCounts(): array
     {
         return $this->brokenLinkRepository->getNumberOfBrokenLinksForRecordsOnPages($this->pids, $this->searchFields);
     }
diff --git a/typo3/sysext/linkvalidator/Classes/Result/LinkAnalyzerResult.php b/typo3/sysext/linkvalidator/Classes/Result/LinkAnalyzerResult.php
index 7f423053aa46..e89a39d55380 100644
--- a/typo3/sysext/linkvalidator/Classes/Result/LinkAnalyzerResult.php
+++ b/typo3/sysext/linkvalidator/Classes/Result/LinkAnalyzerResult.php
@@ -36,77 +36,28 @@ use TYPO3\CMS\Linkvalidator\Repository\PagesRepository;
  */
 class LinkAnalyzerResult
 {
-    /**
-     * @var LinkAnalyzer
-     */
-    protected $linkAnalyzer;
-
-    /**
-     * @var BrokenLinkRepository
-     */
-    protected $brokenLinkRepository;
-
-    /**
-     * @var PagesRepository
-     */
-    protected $pagesRepository;
-
-    /**
-     * @var ConnectionPool
-     */
-    protected $connectionPool;
-
-    /**
-     * @var array
-     */
-    protected $brokenLinks = [];
-
-    /**
-     * @var array
-     */
-    protected $newBrokenLinkCounts = [];
-
-    /**
-     * @var array
-     */
-    protected $oldBrokenLinkCounts = [];
-
-    /**
-     * @var bool
-     */
-    protected $differentToLastResult = false;
+    protected array $brokenLinks = [];
+    protected array $newBrokenLinkCounts = [];
+    protected array $oldBrokenLinkCounts = [];
+    protected bool $differentToLastResult = false;
 
     /**
      * Save localized pages to reduce database requests
      *
      * @var array<string, int>
      */
-    protected $localizedPages = [];
+    protected array $localizedPages = [];
 
     public function __construct(
-        LinkAnalyzer $linkAnalyzer,
-        BrokenLinkRepository $brokenLinkRepository,
-        ConnectionPool $connectionPool,
-        PagesRepository $pagesRepository
+        private readonly LinkAnalyzer $linkAnalyzer,
+        private readonly BrokenLinkRepository $brokenLinkRepository,
+        private readonly ConnectionPool $connectionPool,
+        private readonly PagesRepository $pagesRepository
     ) {
-        $this->linkAnalyzer = $linkAnalyzer;
-        $this->brokenLinkRepository = $brokenLinkRepository;
-        $this->connectionPool = $connectionPool;
-        $this->pagesRepository = $pagesRepository;
     }
 
     /**
      * Call LinkAnalyzer with provided task configuration and process result values
-     *
-     * @param int    $page
-     * @param int    $depth
-     * @param array  $pageRow
-     * @param array  $modTSconfig
-     * @param array  $searchFields
-     * @param array  $linkTypes
-     * @param string $languages
-     *
-     * @return $this
      */
     public function getResultForTask(
         int $page,
@@ -213,7 +164,6 @@ class LinkAnalyzerResult
      * Process the link counts (old and new) and ensures that all link types are available in the array
      *
      * @param array<int, string> $linkTypes list of link types
-     * @return LinkAnalyzerResult
      */
     protected function processLinkCounts(array $linkTypes): self
     {
@@ -236,12 +186,10 @@ class LinkAnalyzerResult
      * Process broken link values and assign them to new variables which are used in the templates
      * shipped by the core but can also be used in custom templates. The raw data is untouched and
      * can also still be used in custom templates.
-     *
-     * @return LinkAnalyzerResult
      */
     protected function processBrokenLinks(): self
     {
-        foreach ($this->brokenLinks as $key => &$brokenLink) {
+        foreach ($this->brokenLinks as &$brokenLink) {
             $fullRecord = BackendUtility::getRecord($brokenLink['table_name'], $brokenLink['record_uid']);
 
             if ($fullRecord !== null) {
@@ -274,10 +222,6 @@ class LinkAnalyzerResult
 
     /**
      * Get localized page id and store it in the local property localizedPages
-     *
-     * @param int $parentId
-     * @param int $languageId
-     * @return int
      */
     protected function getLocalizedPageId(int $parentId, int $languageId): int
     {
diff --git a/typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php b/typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php
index 56af6dcd4ad1..62d1bc0aa581 100644
--- a/typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php
+++ b/typo3/sysext/linkvalidator/Classes/Task/ValidatorTask.php
@@ -134,7 +134,6 @@ class ValidatorTask extends AbstractTask
      * Set the value of the private property email.
      *
      * @param string $email Email address to which an email report is sent
-     * @return ValidatorTask
      */
     public function setEmail(string $email): self
     {
@@ -156,7 +155,6 @@ class ValidatorTask extends AbstractTask
      * Set the value of the private property emailOnBrokenLinkOnly
      *
      * @param bool $emailOnBrokenLinkOnly Only send an email, if new broken links were found
-     * @return ValidatorTask
      */
     public function setEmailOnBrokenLinkOnly(bool $emailOnBrokenLinkOnly): self
     {
@@ -178,7 +176,6 @@ class ValidatorTask extends AbstractTask
      * Set the value of the private property page
      *
      * @param int $page UID of the start page for this task.
-     * @return ValidatorTask
      */
     public function setPage(int $page): self
     {
@@ -200,7 +197,6 @@ class ValidatorTask extends AbstractTask
      * Set the value of the private property languages
      *
      * @param string $languages Languages to fetch broken links
-     * @return ValidatorTask
      */
     public function setLanguages(string $languages): self
     {
@@ -222,7 +218,6 @@ class ValidatorTask extends AbstractTask
      * Set the value of the private property depth
      *
      * @param int $depth Level of pages the task should check
-     * @return ValidatorTask
      */
     public function setDepth(int $depth): self
     {
@@ -244,7 +239,6 @@ class ValidatorTask extends AbstractTask
      * Set the value of the private property emailTemplateName
      *
      * @param string $emailTemplateName Template name to be used for the email
-     * @return ValidatorTask
      */
     public function setEmailTemplateName(string $emailTemplateName): self
     {
@@ -266,7 +260,6 @@ class ValidatorTask extends AbstractTask
      * Set the value of the private property configuration
      *
      * @param string $configuration specific TSconfig for this task
-     * @return ValidatorTask
      */
     public function setConfiguration(string $configuration): self
     {
@@ -285,9 +278,7 @@ class ValidatorTask extends AbstractTask
             return false;
         }
 
-        $this
-            ->setCliArguments()
-            ->loadModTSconfig();
+        $this->setCliArguments()->loadModTSconfig();
 
         $successfullyExecuted = true;
         $linkAnalyzerResult = $this->getLinkAnalyzerResult();
@@ -309,8 +300,6 @@ class ValidatorTask extends AbstractTask
     /**
      * Validate all broken links for pages set in the task configuration
      * and return the analyzers result as object.
-     *
-     * @return LinkAnalyzerResult
      */
     protected function getLinkAnalyzerResult(): LinkAnalyzerResult
     {
@@ -336,10 +325,8 @@ class ValidatorTask extends AbstractTask
 
     /**
      * Load and merge linkvalidator TSconfig from task configuration with page TSconfig
-     *
-     * @return ValidatorTask
      */
-    protected function loadModTSconfig(): self
+    protected function loadModTSconfig(): void
     {
         $parseObj = GeneralUtility::makeInstance(TypoScriptParser::class);
         $parseObj->parse($this->configuration);
@@ -355,6 +342,7 @@ class ValidatorTask extends AbstractTask
         if (is_array($overrideTs) && $overrideTs !== []) {
             ArrayUtility::mergeRecursiveWithOverrule($modTs, $overrideTs);
         }
+
         if (empty($modTs['mail.']['fromemail'])) {
             $modTs['mail.']['fromemail'] = MailUtility::getSystemFromAddress();
         }
@@ -363,8 +351,6 @@ class ValidatorTask extends AbstractTask
         }
 
         $this->modTSconfig = $modTs;
-
-        return $this;
     }
 
     /**
@@ -404,8 +390,7 @@ class ValidatorTask extends AbstractTask
     /**
      * Build and send report email when broken links were found
      *
-     * @param LinkAnalyzerResult $linkAnalyzerResult
-     * @return bool TRUE if mail was sent, FALSE if or not
+     * @return bool TRUE if mail was sent, FALSE if not
      */
     protected function reportEmail(LinkAnalyzerResult $linkAnalyzerResult): bool
     {
@@ -478,8 +463,6 @@ class ValidatorTask extends AbstractTask
     /**
      * Returns the most important properties of the LinkValidator task as a
      * comma separated string that will be displayed in the scheduler module.
-     *
-     * @return string
      */
     public function getAdditionalInformation(): string
     {
@@ -505,8 +488,6 @@ class ValidatorTask extends AbstractTask
 
     /**
      * Simulate cli call with setting the required options to the $_SERVER['argv']
-     *
-     * @return ValidatorTask
      */
     protected function setCliArguments(): self
     {
@@ -528,8 +509,6 @@ class ValidatorTask extends AbstractTask
 
     /**
      * Get FluidEmail with template from the task configuration
-     *
-     * @return FluidEmail
      */
     protected function getFluidEmail(): FluidEmail
     {
@@ -557,9 +536,6 @@ class ValidatorTask extends AbstractTask
 
     /**
      * Check if both template files (html and txt) exist under at least one template path
-     *
-     * @param array $templatePaths
-     * @return bool
      */
     protected function templateFilesExist(array $templatePaths): bool
     {
-- 
GitLab