From 2aff2fe6557b873451533eba2cd4d957fb660d3a Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Sat, 19 Nov 2022 14:51:51 +0100
Subject: [PATCH] [TASK] Have some more strict typing

Resolves: #99139
Releases: main
Change-Id: I398300c9db862f4207c21386fc461d98a1e6fc6d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/76707
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: Nikita Hovratov <nikita.h@live.de>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
---
 Build/phpstan/phpstan-baseline.neon           | 30 -------------------
 .../StandardContentPreviewRenderer.php        |  2 +-
 .../Classes/Utility/BackendUtility.php        |  3 +-
 .../BackendLayout/Grid/GridColumnItem.php     |  2 +-
 .../Tests/Unit/Utility/BackendUtilityTest.php |  6 ++--
 .../Mfa/MfaProviderPropertyManager.php        |  6 +---
 6 files changed, 7 insertions(+), 42 deletions(-)

diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon
index f48d317bd248..1f2aee62ec05 100644
--- a/Build/phpstan/phpstan-baseline.neon
+++ b/Build/phpstan/phpstan-baseline.neon
@@ -240,11 +240,6 @@ parameters:
 			count: 2
 			path: ../../typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php
 
-		-
-			message: "#^Parameter \\#1 \\$pageId of static method TYPO3\\\\CMS\\\\Backend\\\\Utility\\\\BackendUtility\\:\\:getLabelFromItemListMerged\\(\\) expects int, string given\\.$#"
-			count: 1
-			path: ../../typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
-
 		-
 			message: "#^Property TYPO3\\\\CMS\\\\Belog\\\\Domain\\\\Model\\\\LogEntry\\:\\:\\$newId \\(string\\) does not accept default value of type int\\.$#"
 			count: 1
@@ -300,26 +295,6 @@ parameters:
 			count: 1
 			path: ../../typo3/sysext/core/Classes/Authentication/IpLocker.php
 
-		-
-			message: "#^Parameter \\#2 \\$default of method TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\Mfa\\\\MfaProviderPropertyManager\\:\\:getProperty\\(\\) expects null, array given\\.$#"
-			count: 4
-			path: ../../typo3/sysext/core/Classes/Authentication/Mfa/Provider/RecoveryCodesProvider.php
-
-		-
-			message: "#^Parameter \\#2 \\$default of method TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\Mfa\\\\MfaProviderPropertyManager\\:\\:getProperty\\(\\) expects null, int given\\.$#"
-			count: 5
-			path: ../../typo3/sysext/core/Classes/Authentication/Mfa/Provider/RecoveryCodesProvider.php
-
-		-
-			message: "#^Parameter \\#2 \\$default of method TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\Mfa\\\\MfaProviderPropertyManager\\:\\:getProperty\\(\\) expects null, int given\\.$#"
-			count: 4
-			path: ../../typo3/sysext/core/Classes/Authentication/Mfa/Provider/TotpProvider.php
-
-		-
-			message: "#^Parameter \\#2 \\$default of method TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\Mfa\\\\MfaProviderPropertyManager\\:\\:getProperty\\(\\) expects null, string given\\.$#"
-			count: 2
-			path: ../../typo3/sysext/core/Classes/Authentication/Mfa/Provider/TotpProvider.php
-
 		-
 			message: "#^Parameter \\#1 \\$key1 of method Redis\\:\\:sUnion\\(\\) expects string, array\\<int, string\\> given\\.$#"
 			count: 1
@@ -1260,11 +1235,6 @@ parameters:
 			count: 1
 			path: ../../typo3/sysext/core/Classes/Utility/IpAnonymizationUtility.php
 
-		-
-			message: "#^Parameter \\#2 \\$default of method TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\Mfa\\\\MfaProviderPropertyManager\\:\\:getProperty\\(\\) expects null, string given\\.$#"
-			count: 1
-			path: ../../typo3/sysext/core/Tests/Functional/Authentication/Mfa/MfaProviderPropertyManagerTest.php
-
 		-
 			message: "#^Parameter \\#2 \\$data of method TYPO3\\\\CMS\\\\Core\\\\Cache\\\\Backend\\\\FileBackend\\:\\:set\\(\\) expects string, array\\<int, string\\> given\\.$#"
 			count: 1
diff --git a/typo3/sysext/backend/Classes/Preview/StandardContentPreviewRenderer.php b/typo3/sysext/backend/Classes/Preview/StandardContentPreviewRenderer.php
index 2a7f8dd5ea77..a2ca776742de 100644
--- a/typo3/sysext/backend/Classes/Preview/StandardContentPreviewRenderer.php
+++ b/typo3/sysext/backend/Classes/Preview/StandardContentPreviewRenderer.php
@@ -144,7 +144,7 @@ class StandardContentPreviewRenderer implements PreviewRendererInterface, Logger
                 break;
             case 'list':
                 if (!empty($record['list_type'])) {
-                    $label = BackendUtility::getLabelFromItemListMerged($record['pid'], 'tt_content', 'list_type', $record['list_type']);
+                    $label = BackendUtility::getLabelFromItemListMerged((int)$record['pid'], 'tt_content', 'list_type', $record['list_type']);
                     if (!empty($label)) {
                         $out .= $this->linkEditContent('<strong>' . htmlspecialchars($languageService->sL($label)) . '</strong>', $record);
                     } else {
diff --git a/typo3/sysext/backend/Classes/Utility/BackendUtility.php b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
index f3b49d186a45..71783f7a66c5 100644
--- a/typo3/sysext/backend/Classes/Utility/BackendUtility.php
+++ b/typo3/sysext/backend/Classes/Utility/BackendUtility.php
@@ -1279,13 +1279,12 @@ class BackendUtility
     /**
      * Return the label of a field by additionally checking TsConfig values
      *
-     * @param int $pageId Page id
      * @param string $table Table name
      * @param string $column Field Name
      * @param string $key item value
      * @return string Label for item entry
      */
-    public static function getLabelFromItemListMerged($pageId, $table, $column, $key)
+    public static function getLabelFromItemListMerged(int $pageId, $table, $column, $key)
     {
         $pageTsConfig = static::getPagesTSconfig($pageId);
         $label = '';
diff --git a/typo3/sysext/backend/Classes/View/BackendLayout/Grid/GridColumnItem.php b/typo3/sysext/backend/Classes/View/BackendLayout/Grid/GridColumnItem.php
index 44e12cbde6df..c8127d079b82 100644
--- a/typo3/sysext/backend/Classes/View/BackendLayout/Grid/GridColumnItem.php
+++ b/typo3/sysext/backend/Classes/View/BackendLayout/Grid/GridColumnItem.php
@@ -165,7 +165,7 @@ class GridColumnItem extends AbstractGridObject
         $contentTypeLabels = $this->context->getContentTypeLabels();
         $ctype = $this->record['CType'] ?? '';
         return $contentTypeLabels[$ctype] ??
-            BackendUtility::getLabelFromItemListMerged($this->record['pid'], 'tt_content', 'CType', $ctype);
+            BackendUtility::getLabelFromItemListMerged((int)$this->record['pid'], 'tt_content', 'CType', $ctype);
     }
 
     public function getIcons(): string
diff --git a/typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php b/typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
index e9113b00f538..d83db8507839 100644
--- a/typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
+++ b/typo3/sysext/backend/Tests/Unit/Utility/BackendUtilityTest.php
@@ -796,7 +796,7 @@ class BackendUtilityTest extends UnitTestCase
     {
         return [
             'no field found' => [
-                'pageId' => '123',
+                'pageId' => 123,
                 'table' => 'tt_content',
                 'col' => 'menu_type',
                 'key' => '10',
@@ -816,7 +816,7 @@ class BackendUtilityTest extends UnitTestCase
                 'expectedLabel' => '',
             ],
             'no tsconfig set' => [
-                'pageId' => '123',
+                'pageId' => 123,
                 'table' => 'tt_content',
                 'col' => 'menu_type',
                 'key' => '1',
@@ -843,7 +843,7 @@ class BackendUtilityTest extends UnitTestCase
      * @dataProvider getLabelFromItemListMergedReturnsCorrectFieldsDataProvider
      */
     public function getLabelFromItemListMergedReturnsCorrectFields(
-        string $pageId,
+        int $pageId,
         string $table,
         string $column,
         string $key,
diff --git a/typo3/sysext/core/Classes/Authentication/Mfa/MfaProviderPropertyManager.php b/typo3/sysext/core/Classes/Authentication/Mfa/MfaProviderPropertyManager.php
index b364d0d77696..c6e20c8b17a4 100644
--- a/typo3/sysext/core/Classes/Authentication/Mfa/MfaProviderPropertyManager.php
+++ b/typo3/sysext/core/Classes/Authentication/Mfa/MfaProviderPropertyManager.php
@@ -73,12 +73,8 @@ class MfaProviderPropertyManager implements LoggerAwareInterface
     /**
      * Get a provider specific property value or the defined
      * default value if the requested property was not found.
-     *
-     * @param string $key
-     * @param null $default
-     * @return mixed|null
      */
-    public function getProperty(string $key, $default = null)
+    public function getProperty(string $key, mixed $default = null): mixed
     {
         return $this->providerProperties[$key] ?? $default;
     }
-- 
GitLab