From 156998aac0e37f9a437bffd6374b9b48a8c05d3a Mon Sep 17 00:00:00 2001
From: Torben Hansen <derhansen@gmail.com>
Date: Mon, 13 Mar 2023 19:44:07 +0100
Subject: [PATCH] [TASK] Cleanup ext:lowlevel

This change cleans up parts of ext:lowlevel by

* using constructor property promotion where possible
* using typesafe comparison for command option `dry-run`
* removing superfluous typehints in doc headers
* adding missing typehints in doc headers
* using strict comparison where possible
* adding function parameter type declaration where suitable
* adding missing function return types
* fixing a typo in `ProviderRegistry`

Resolves: #100158
Releases: main
Signed-off-by: Torben Hansen <derhansen@gmail.com>
Change-Id: I9a3cbf09652d1fec586f89965569c7d087bc7aa0
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78110
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Benni Mack <benni@typo3.org>
---
 .../Classes/Command/CleanFlexFormsCommand.php | 15 ++---------
 .../Classes/Command/DeletedRecordsCommand.php | 18 +++----------
 .../Command/MissingRelationsCommand.php       | 20 ++++-----------
 .../Classes/Command/OrphanRecordsCommand.php  | 14 +++--------
 .../BackendRoutesProvider.php                 |  5 +---
 .../EventListenersProvider.php                |  5 +---
 .../HttpMiddlewareStackProvider.php           |  5 +---
 .../MfaProvidersProvider.php                  |  5 +---
 .../ProviderInterface.php                     |  1 -
 .../ProviderRegistry.php                      |  4 +--
 .../SoftReferenceParsersProvider.php          |  5 +---
 .../ToolbarItemsProvider.php                  |  5 +---
 .../DatabaseIntegrityController.php           | 25 ++++++-------------
 13 files changed, 31 insertions(+), 96 deletions(-)

diff --git a/typo3/sysext/lowlevel/Classes/Command/CleanFlexFormsCommand.php b/typo3/sysext/lowlevel/Classes/Command/CleanFlexFormsCommand.php
index 555796db6e60..d7a9810bb99c 100644
--- a/typo3/sysext/lowlevel/Classes/Command/CleanFlexFormsCommand.php
+++ b/typo3/sysext/lowlevel/Classes/Command/CleanFlexFormsCommand.php
@@ -36,14 +36,8 @@ use TYPO3\CMS\Core\Utility\MathUtility;
  */
 class CleanFlexFormsCommand extends Command
 {
-    /**
-     * @var ConnectionPool
-     */
-    private $connectionPool;
-
-    public function __construct(ConnectionPool $connectionPool)
+    public function __construct(private readonly ConnectionPool $connectionPool)
     {
-        $this->connectionPool = $connectionPool;
         parent::__construct();
     }
 
@@ -99,8 +93,7 @@ class CleanFlexFormsCommand extends Command
             $io->section('Searching the database now for records with FlexForms that need to be updated.');
         }
 
-        // Type unsafe comparison and explicit boolean setting on purpose
-        $dryRun = $input->hasOption('dry-run') && $input->getOption('dry-run') != false ? true : false;
+        $dryRun = $input->hasOption('dry-run') && (bool)$input->getOption('dry-run') !== false;
 
         // Find all records that should be updated
         $recordsToUpdate = $this->findAllDirtyFlexformsInPage($startingPoint, $depth);
@@ -124,10 +117,6 @@ class CleanFlexFormsCommand extends Command
 
     /**
      * Recursive traversal of page tree
-     *
-     * @param int $pageId Page root id
-     * @param int $depth Depth
-     * @param array $dirtyFlexFormFields the list of all previously found flexform fields
      */
     protected function findAllDirtyFlexformsInPage(int $pageId, int $depth, array $dirtyFlexFormFields = []): array
     {
diff --git a/typo3/sysext/lowlevel/Classes/Command/DeletedRecordsCommand.php b/typo3/sysext/lowlevel/Classes/Command/DeletedRecordsCommand.php
index 4df1dbdafd3e..cfd4aa409075 100644
--- a/typo3/sysext/lowlevel/Classes/Command/DeletedRecordsCommand.php
+++ b/typo3/sysext/lowlevel/Classes/Command/DeletedRecordsCommand.php
@@ -35,14 +35,8 @@ use TYPO3\CMS\Core\Utility\MathUtility;
  */
 class DeletedRecordsCommand extends Command
 {
-    /**
-     * @var ConnectionPool
-     */
-    private $connectionPool;
-
-    public function __construct(ConnectionPool $connectionPool)
+    public function __construct(private readonly ConnectionPool $connectionPool)
     {
-        $this->connectionPool = $connectionPool;
         parent::__construct();
     }
 
@@ -111,8 +105,7 @@ class DeletedRecordsCommand extends Command
             $io->section('Searching the database now for deleted records.');
         }
 
-        // type unsafe comparison and explicit boolean setting on purpose
-        $dryRun = $input->hasOption('dry-run') && $input->getOption('dry-run') != false ? true : false;
+        $dryRun = $input->hasOption('dry-run') && (bool)$input->getOption('dry-run') !== false;
 
         // find all records that should be deleted
         $deletedRecords = $this->findAllFlaggedRecordsInPage($startingPoint, $depth, $maximumTimestamp);
@@ -284,10 +277,7 @@ class DeletedRecordsCommand extends Command
     }
 
     /**
-     * Fetches all tables registered in the TCA with a $flag
-     * and that are not pages (which are handled separately)
-     *
-     * @return array an associative array with the table as key and the
+     * Fetches all tables registered in the TCA with a $flag and that are not pages (which are handled separately).
      */
     protected function getTablesWithFlag(string $flag): array
     {
@@ -307,7 +297,7 @@ class DeletedRecordsCommand extends Command
      * @param array $deletedRecords two level array with tables and uids
      * @param bool $dryRun check if the records should NOT be deleted (use --dry-run to avoid)
      */
-    protected function deleteRecords(array $deletedRecords, bool $dryRun, SymfonyStyle $io)
+    protected function deleteRecords(array $deletedRecords, bool $dryRun, SymfonyStyle $io): void
     {
         // Putting "pages" table in the bottom
         if (isset($deletedRecords['pages'])) {
diff --git a/typo3/sysext/lowlevel/Classes/Command/MissingRelationsCommand.php b/typo3/sysext/lowlevel/Classes/Command/MissingRelationsCommand.php
index adcf023c1bd6..ce6b26ded9aa 100644
--- a/typo3/sysext/lowlevel/Classes/Command/MissingRelationsCommand.php
+++ b/typo3/sysext/lowlevel/Classes/Command/MissingRelationsCommand.php
@@ -43,16 +43,11 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  */
 class MissingRelationsCommand extends Command
 {
-    /**
-     * @var ConnectionPool
-     */
-    private $connectionPool;
-
-    public function __construct(ConnectionPool $connectionPool)
+    public function __construct(private readonly ConnectionPool $connectionPool)
     {
-        $this->connectionPool = $connectionPool;
         parent::__construct();
     }
+
     /**
      * Configure the command by defining the name, options and arguments
      */
@@ -113,7 +108,7 @@ If you want to get more detailed information, use the --verbose option.')
         $io = new SymfonyStyle($input, $output);
         $io->title($this->getDescription());
 
-        $dryRun = $input->hasOption('dry-run') && $input->getOption('dry-run') != false ? true : false;
+        $dryRun = $input->hasOption('dry-run') && (bool)$input->getOption('dry-run') !== false;
 
         // Update the reference index
         $this->updateReferenceIndex($input, $io);
@@ -190,11 +185,8 @@ If you want to get more detailed information, use the --verbose option.')
      * - if the option --update-refindex is set, do it
      * - otherwise, if in interactive mode (not having -n set), ask the user
      * - otherwise assume everything is fine
-     *
-     * @param InputInterface $input holds information about entered parameters
-     * @param SymfonyStyle $io necessary for outputting information
      */
-    protected function updateReferenceIndex(InputInterface $input, SymfonyStyle $io)
+    protected function updateReferenceIndex(InputInterface $input, SymfonyStyle $io): void
     {
         // Check for reference index to update
         $io->note('Finding missing records referenced by TYPO3 requires a clean reference index (sys_refindex)');
@@ -219,8 +211,6 @@ If you want to get more detailed information, use the --verbose option.')
 
     /**
      * Find relations pointing to non-existing records (in managed references or soft-references)
-     *
-     * @return array an array of records within sys_refindex
      */
     protected function findRelationsToNonExistingRecords(): array
     {
@@ -340,7 +330,7 @@ If you want to get more detailed information, use the --verbose option.')
         array $nonExistingRecords,
         bool $dryRun,
         SymfonyStyle $io
-    ) {
+    ): void {
         // Remove references to offline records
         foreach ($offlineVersionRecords as $fileName => $references) {
             if ($io->isVeryVerbose()) {
diff --git a/typo3/sysext/lowlevel/Classes/Command/OrphanRecordsCommand.php b/typo3/sysext/lowlevel/Classes/Command/OrphanRecordsCommand.php
index 91d5da18c9de..009f465d29ba 100644
--- a/typo3/sysext/lowlevel/Classes/Command/OrphanRecordsCommand.php
+++ b/typo3/sysext/lowlevel/Classes/Command/OrphanRecordsCommand.php
@@ -34,16 +34,11 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  */
 class OrphanRecordsCommand extends Command
 {
-    /**
-     * @var ConnectionPool
-     */
-    private $connectionPool;
-
-    public function __construct(ConnectionPool $connectionPool)
+    public function __construct(private readonly ConnectionPool $connectionPool)
     {
-        $this->connectionPool = $connectionPool;
         parent::__construct();
     }
+
     /**
      * Configure the command by defining the name, options and arguments
      */
@@ -86,8 +81,7 @@ Manual repair suggestions:
             $io->section('Searching the database now for orphaned records.');
         }
 
-        // type unsafe comparison and explicit boolean setting on purpose
-        $dryRun = $input->hasOption('dry-run') && $input->getOption('dry-run') != false ? true : false;
+        $dryRun = $input->hasOption('dry-run') && (bool)$input->getOption('dry-run') !== false;
 
         // find all records that should be deleted
         $allRecords = $this->findAllConnectedRecordsInPage(0, 10000);
@@ -240,7 +234,7 @@ Manual repair suggestions:
      * @param array $orphanedRecords two level array with tables and uids
      * @param bool $dryRun check if the records should NOT be deleted (use --dry-run to avoid)
      */
-    protected function deleteRecords(array $orphanedRecords, bool $dryRun, SymfonyStyle $io)
+    protected function deleteRecords(array $orphanedRecords, bool $dryRun, SymfonyStyle $io): void
     {
         // Putting "pages" table in the bottom
         if (isset($orphanedRecords['pages'])) {
diff --git a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/BackendRoutesProvider.php b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/BackendRoutesProvider.php
index dcfaacb1e131..58a3062cd3af 100644
--- a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/BackendRoutesProvider.php
+++ b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/BackendRoutesProvider.php
@@ -24,11 +24,8 @@ use TYPO3\CMS\Core\Utility\ArrayUtility;
 
 class BackendRoutesProvider extends AbstractProvider
 {
-    protected Router $router;
-
-    public function __construct(Router $router)
+    public function __construct(protected readonly Router $router)
     {
-        $this->router = $router;
     }
 
     public function getConfiguration(): array
diff --git a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/EventListenersProvider.php b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/EventListenersProvider.php
index 134e3d4ef69a..aae48d3ae603 100644
--- a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/EventListenersProvider.php
+++ b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/EventListenersProvider.php
@@ -21,11 +21,8 @@ use TYPO3\CMS\Core\EventDispatcher\ListenerProvider;
 
 class EventListenersProvider extends AbstractProvider
 {
-    protected ListenerProvider $listenerProvider;
-
-    public function __construct(ListenerProvider $listenerProvider)
+    public function __construct(protected readonly ListenerProvider $listenerProvider)
     {
-        $this->listenerProvider = $listenerProvider;
     }
 
     public function getConfiguration(): array
diff --git a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/HttpMiddlewareStackProvider.php b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/HttpMiddlewareStackProvider.php
index 2a2b31f76c20..f70443ba9ce4 100644
--- a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/HttpMiddlewareStackProvider.php
+++ b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/HttpMiddlewareStackProvider.php
@@ -21,11 +21,8 @@ use Psr\Container\ContainerInterface;
 
 class HttpMiddlewareStackProvider extends AbstractProvider
 {
-    protected ContainerInterface $container;
-
-    public function __construct(ContainerInterface $container)
+    public function __construct(protected readonly ContainerInterface $container)
     {
-        $this->container = $container;
     }
 
     public function getConfiguration(): array
diff --git a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/MfaProvidersProvider.php b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/MfaProvidersProvider.php
index 90de802d2253..6476d5b92822 100644
--- a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/MfaProvidersProvider.php
+++ b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/MfaProvidersProvider.php
@@ -21,11 +21,8 @@ use TYPO3\CMS\Core\Authentication\Mfa\MfaProviderRegistry;
 
 class MfaProvidersProvider extends AbstractProvider
 {
-    protected MfaProviderRegistry $mfaProviderRegistry;
-
-    public function __construct(MfaProviderRegistry $mfaProviderRegistry)
+    public function __construct(protected MfaProviderRegistry $mfaProviderRegistry)
     {
-        $this->mfaProviderRegistry = $mfaProviderRegistry;
     }
 
     public function getConfiguration(): array
diff --git a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ProviderInterface.php b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ProviderInterface.php
index b80b2a625e43..01629aa0adc6 100644
--- a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ProviderInterface.php
+++ b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ProviderInterface.php
@@ -29,7 +29,6 @@ interface ProviderInterface
      * Note: We use __invoke so provider implementations are still
      * able to use dependency injection via constructor arguments.
      *
-     * @param array $attributes
      * @return $this
      */
     public function __invoke(array $attributes): self;
diff --git a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ProviderRegistry.php b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ProviderRegistry.php
index 2e9ed598ebb3..468d92a7348d 100644
--- a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ProviderRegistry.php
+++ b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ProviderRegistry.php
@@ -32,9 +32,9 @@ final class ProviderRegistry
         $this->providers[$attributes['identifier']] = $provider($attributes);
     }
 
-    public function hasProvider(string $identifer): bool
+    public function hasProvider(string $identifier): bool
     {
-        return isset($this->providers[$identifer]);
+        return isset($this->providers[$identifier]);
     }
 
     public function getProvider(string $identifier): ProviderInterface
diff --git a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/SoftReferenceParsersProvider.php b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/SoftReferenceParsersProvider.php
index b606832181ae..76efcce8adc1 100644
--- a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/SoftReferenceParsersProvider.php
+++ b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/SoftReferenceParsersProvider.php
@@ -21,11 +21,8 @@ use TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserFactory;
 
 class SoftReferenceParsersProvider extends AbstractProvider
 {
-    protected SoftReferenceParserFactory $softReferenceParserFactory;
-
-    public function __construct(SoftReferenceParserFactory $softReferenceParserFactory)
+    public function __construct(protected SoftReferenceParserFactory $softReferenceParserFactory)
     {
-        $this->softReferenceParserFactory = $softReferenceParserFactory;
     }
 
     public function getConfiguration(): array
diff --git a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ToolbarItemsProvider.php b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ToolbarItemsProvider.php
index 1a697151f249..68e37e5cbc3e 100644
--- a/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ToolbarItemsProvider.php
+++ b/typo3/sysext/lowlevel/Classes/ConfigurationModuleProvider/ToolbarItemsProvider.php
@@ -21,11 +21,8 @@ use TYPO3\CMS\Backend\Toolbar\ToolbarItemsRegistry;
 
 class ToolbarItemsProvider extends AbstractProvider
 {
-    protected ToolbarItemsRegistry $toolbarItemsRegistry;
-
-    public function __construct(ToolbarItemsRegistry $toolbarItemsRegistry)
+    public function __construct(protected readonly ToolbarItemsRegistry $toolbarItemsRegistry)
     {
-        $this->toolbarItemsRegistry = $toolbarItemsRegistry;
     }
 
     public function getConfiguration(): array
diff --git a/typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php b/typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php
index c919db762756..cc0f5a57e211 100644
--- a/typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php
+++ b/typo3/sysext/lowlevel/Classes/Controller/DatabaseIntegrityController.php
@@ -71,10 +71,6 @@ class DatabaseIntegrityController
      */
     protected array $MOD_SETTINGS = [];
 
-    protected IconFactory $iconFactory;
-    protected UriBuilder $uriBuilder;
-    protected ModuleTemplateFactory $moduleTemplateFactory;
-
     protected string $formName = '';
     protected string $moduleName = '';
 
@@ -220,13 +216,10 @@ class DatabaseIntegrityController
     ];
 
     public function __construct(
-        IconFactory $iconFactory,
-        UriBuilder $uriBuilder,
-        ModuleTemplateFactory $moduleTemplateFactory
+        protected IconFactory $iconFactory,
+        protected readonly UriBuilder $uriBuilder,
+        protected readonly ModuleTemplateFactory $moduleTemplateFactory
     ) {
-        $this->iconFactory = $iconFactory;
-        $this->uriBuilder = $uriBuilder;
-        $this->moduleTemplateFactory = $moduleTemplateFactory;
         $this->moduleName = 'system_dbint';
     }
 
@@ -620,7 +613,7 @@ class DatabaseIntegrityController
         if ($id < 0) {
             $id = abs($id);
         }
-        if ($begin == 0) {
+        if ($begin === 0) {
             $theList = (string)$id;
         } else {
             $theList = '';
@@ -749,7 +742,7 @@ class DatabaseIntegrityController
     /**
      * @param array|null $row Table columns
      */
-    protected function resultRowTitles($row, array $conf): string
+    protected function resultRowTitles(?array $row, array $conf): string
     {
         $languageService = $this->getLanguageService();
         $tableHeader = [];
@@ -1061,7 +1054,7 @@ class DatabaseIntegrityController
             $tablePrefix = '';
             $labelFieldSelect = [];
             foreach ($from_table_Arr as $from_table) {
-                if ($useTablePrefix && !$dontPrefixFirstTable && $counter != 1 || $counter == 1) {
+                if ($useTablePrefix && !$dontPrefixFirstTable && $counter !== 1 || $counter === 1) {
                     $tablePrefix = $from_table . '_';
                 }
                 $counter = 1;
@@ -1298,10 +1291,8 @@ class DatabaseIntegrityController
 
     /**
      * Checks if the given value is of the ISO 8601 format.
-     *
-     * @param mixed $date
      */
-    protected function isDateOfIso8601Format($date): bool
+    protected function isDateOfIso8601Format(mixed $date): bool
     {
         if (!is_int($date) && !is_string($date)) {
             return false;
@@ -1807,7 +1798,7 @@ class DatabaseIntegrityController
             foreach ($from_table_Arr as $from_table) {
                 $useSelectLabels = false;
                 $useAltSelectLabels = false;
-                if ($useTablePrefix && !$dontPrefixFirstTable && $counter != 1 || $counter === 1) {
+                if ($useTablePrefix && !$dontPrefixFirstTable && $counter !== 1 || $counter === 1) {
                     $tablePrefix = $from_table . '_';
                 }
                 $counter = 1;
-- 
GitLab