From 5155186dc568a0829e1671944fbafe94964b66f4 Mon Sep 17 00:00:00 2001
From: Alexander Schnitzler <git@alexanderschnitzler.de>
Date: Sat, 26 Sep 2020 18:05:34 +0200
Subject: [PATCH] [TASK] Fix phpstan checkFunctionArgumentTypes errors in
 ext:recordlist

This patch fixes incompatible type usage in function arguments
and is preparatory work for introducing native type hints and
strict mode in all core files.

Resolves: #92172
Releases: master, 10.4
Change-Id: I9c01e01e6d085acc5e9399ba307b082436bb34b5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65905
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 .../Classes/Browser/AbstractElementBrowser.php           | 4 ++--
 typo3/sysext/recordlist/Classes/Browser/FileBrowser.php  | 4 ++--
 .../Classes/Controller/AbstractLinkBrowserController.php | 2 +-
 .../Classes/Controller/RecordListController.php          | 2 +-
 .../recordlist/Classes/LinkHandler/FileLinkHandler.php   | 2 +-
 .../recordlist/Classes/RecordList/DatabaseRecordList.php | 9 +++++----
 6 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/typo3/sysext/recordlist/Classes/Browser/AbstractElementBrowser.php b/typo3/sysext/recordlist/Classes/Browser/AbstractElementBrowser.php
index a806ddcbcff5..066c325bc2ca 100644
--- a/typo3/sysext/recordlist/Classes/Browser/AbstractElementBrowser.php
+++ b/typo3/sysext/recordlist/Classes/Browser/AbstractElementBrowser.php
@@ -132,14 +132,14 @@ abstract class AbstractElementBrowser
     }
 
     /**
-     * @return string[] Array of body-tag attributes
+     * @return array<string, string> Array of body-tag attributes
      */
     abstract protected function getBodyTagAttributes();
 
     /**
      * Splits parts of $this->bparams and returns needed data attributes for the Javascript
      *
-     * @return string[] Data attributes for Javascript
+     * @return array<string, string> Data attributes for Javascript
      */
     protected function getBParamDataAttributes()
     {
diff --git a/typo3/sysext/recordlist/Classes/Browser/FileBrowser.php b/typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
index 27c7a4a702f0..3aa6a4c55584 100644
--- a/typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
+++ b/typo3/sysext/recordlist/Classes/Browser/FileBrowser.php
@@ -300,9 +300,9 @@ class FileBrowser extends AbstractElementBrowser implements ElementBrowserInterf
                 'fileIcon' => $icon
             ];
             if ($this->fileIsSelectableInFileList($fileObject, $imgInfo)) {
-                $ATag = '<a href="#" class="btn btn-default" title="' . htmlspecialchars($fileObject->getName()) . '" data-file-index="' . htmlspecialchars($filesIndex) . '" data-close="0">';
+                $ATag = '<a href="#" class="btn btn-default" title="' . htmlspecialchars($fileObject->getName()) . '" data-file-index="' . $filesIndex . '" data-close="0">';
                 $ATag .= '<span title="' . htmlspecialchars($lang->getLL('addToList')) . '">' . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render() . '</span>';
-                $ATag_alt = '<a href="#" title="' . htmlspecialchars($fileObject->getName()) . $size . '" data-file-index="' . htmlspecialchars($filesIndex) . '" data-close="1">';
+                $ATag_alt = '<a href="#" title="' . htmlspecialchars($fileObject->getName()) . $size . '" data-file-index="' . $filesIndex . '" data-close="1">';
                 $ATag_e = '</a>';
                 $bulkCheckBox = '<label class="btn btn-default btn-checkbox"><input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /><span class="t3-icon fa"></span></label>';
             } else {
diff --git a/typo3/sysext/recordlist/Classes/Controller/AbstractLinkBrowserController.php b/typo3/sysext/recordlist/Classes/Controller/AbstractLinkBrowserController.php
index 3ba1ccb05da5..21c3e5069003 100644
--- a/typo3/sysext/recordlist/Classes/Controller/AbstractLinkBrowserController.php
+++ b/typo3/sysext/recordlist/Classes/Controller/AbstractLinkBrowserController.php
@@ -254,7 +254,7 @@ abstract class AbstractLinkBrowserController
     /**
      * Reads the configured link handlers from page TSconfig
      *
-     * @return array
+     * @return array<string, array<mixed>>
      */
     protected function getLinkHandlers()
     {
diff --git a/typo3/sysext/recordlist/Classes/Controller/RecordListController.php b/typo3/sysext/recordlist/Classes/Controller/RecordListController.php
index 9086f21907cf..3776503912a7 100644
--- a/typo3/sysext/recordlist/Classes/Controller/RecordListController.php
+++ b/typo3/sysext/recordlist/Classes/Controller/RecordListController.php
@@ -219,7 +219,7 @@ class RecordListController
                 if (!empty($items)) {
                     $cmd = [];
                     foreach ($items as $iK => $value) {
-                        $iKParts = explode('|', $iK);
+                        $iKParts = explode('|', (string)$iK);
                         $cmd[$iKParts[0]][$iKParts[1]]['delete'] = 1;
                     }
                     $tce = GeneralUtility::makeInstance(DataHandler::class);
diff --git a/typo3/sysext/recordlist/Classes/LinkHandler/FileLinkHandler.php b/typo3/sysext/recordlist/Classes/LinkHandler/FileLinkHandler.php
index dbbcb6f7ec7b..b4193e9dddd9 100644
--- a/typo3/sysext/recordlist/Classes/LinkHandler/FileLinkHandler.php
+++ b/typo3/sysext/recordlist/Classes/LinkHandler/FileLinkHandler.php
@@ -202,7 +202,7 @@ class FileLinkHandler extends AbstractLinkHandler implements LinkHandlerInterfac
         }
         // Get size and icon:
         $size = GeneralUtility::formatSize(
-            $fileOrFolderObject->getSize(),
+            (int)$fileOrFolderObject->getSize(),
             $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:byteSizeUnits')
         );
 
diff --git a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
index 56c07beb5430..3dac65aa0ce0 100644
--- a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
+++ b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php
@@ -1563,7 +1563,7 @@ class DatabaseRecordList
      */
     protected function renderListNavigation($renderPart, int $totalItems, int $iLimit, string $table)
     {
-        $totalPages = ceil($totalItems / $iLimit);
+        $totalPages = (int)ceil($totalItems / $iLimit);
         // Show page selector if not all records fit into one page
         if ($totalPages <= 1) {
             return '';
@@ -1572,7 +1572,7 @@ class DatabaseRecordList
         $listURL = $this->listURL('', $this->table, 'firstElementNumber');
         // 1 = first page
         // 0 = first element
-        $currentPage = floor($this->firstElementNumber / $iLimit) + 1;
+        $currentPage = (int)floor($this->firstElementNumber / $iLimit) + 1;
         // Compile first, previous, next, last and refresh buttons
         if ($currentPage > 1) {
             $labelFirst = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:first'));
@@ -1913,7 +1913,7 @@ class DatabaseRecordList
                     $table,
                     $row['uid'],
                     ' ' . $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.referencesToRecord'),
-                    $this->getReferenceCount($table, $row['uid'])
+                    (string)$this->getReferenceCount($table, $row['uid'])
                 ) . BackendUtility::translationCount(
                     $table,
                     $row['uid'],
@@ -2426,6 +2426,7 @@ class DatabaseRecordList
     protected function addHeaderRowToCSV()
     {
         $fieldArray = array_combine($this->fieldArray, $this->fieldArray);
+        $fieldArray = is_array($fieldArray) ? $fieldArray : [];
         $hooks = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][__CLASS__]['customizeCsvHeader'] ?? [];
         if (!empty($hooks)) {
             $hookParameters = [
@@ -3117,7 +3118,7 @@ class DatabaseRecordList
                 // Output the label now:
                 if ($table === 'pages') {
                     $code = '<a href="' . htmlspecialchars(
-                        $this->listURL($uid, '', 'firstElementNumber')
+                        $this->listURL((string)$uid, '', 'firstElementNumber')
                     ) . '" onclick="setHighlight(' . (int)$uid . ')">' . $code . '</a>';
                 } else {
                     $code = $this->linkUrlMail($code, $origCode);
-- 
GitLab