From 2164222a77984056d94515fba307d455a6d8d5ea Mon Sep 17 00:00:00 2001
From: Oliver Klee <typo3-coding@oliverklee.de>
Date: Tue, 28 Jun 2022 18:01:47 +0200
Subject: [PATCH] [BUGFIX] Fix and improve type annotations of the Repository
 base class

This helps reduce warnings when extensions are type-checked with PHPStan.

Resolves: #97820
Releases: main, 11.5

Change-Id: Iee5cd28402d9e33af0bfaa34815552ba331718ee
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74991
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Nikita Hovratov <nikita.h@live.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
---
 Build/phpstan/phpstan-baseline.neon                |  5 -----
 .../Repository/BackendUserGroupRepository.php      |  3 ---
 .../core/Classes/Utility/ClassNamingUtility.php    |  6 ++++++
 .../Domain/Repository/ContentRepository.php        |  3 ---
 .../Domain/Repository/ContentRepository.php        |  3 ---
 .../extbase/Classes/Persistence/Repository.php     | 14 +++++++-------
 6 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon
index 6d197333a78f..359fd1bb6026 100644
--- a/Build/phpstan/phpstan-baseline.neon
+++ b/Build/phpstan/phpstan-baseline.neon
@@ -2540,11 +2540,6 @@ parameters:
 			count: 1
 			path: ../../typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php
 
-		-
-			message: "#^Parameter \\#2 \\$arguments of method TYPO3\\\\CMS\\\\Extbase\\\\Persistence\\\\Repository\\:\\:__call\\(\\) expects string, array given\\.$#"
-			count: 1
-			path: ../../typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php
-
 		-
 			message: "#^Parameter \\#2 \\$key of method TYPO3\\\\CMS\\\\Extbase\\\\Property\\\\PropertyMappingConfiguration\\:\\:getConfigurationValue\\(\\) expects string, int given\\.$#"
 			count: 2
diff --git a/typo3/sysext/beuser/Classes/Domain/Repository/BackendUserGroupRepository.php b/typo3/sysext/beuser/Classes/Domain/Repository/BackendUserGroupRepository.php
index 62e2b334b4f8..66d6fa2534e5 100644
--- a/typo3/sysext/beuser/Classes/Domain/Repository/BackendUserGroupRepository.php
+++ b/typo3/sysext/beuser/Classes/Domain/Repository/BackendUserGroupRepository.php
@@ -24,9 +24,6 @@ use TYPO3\CMS\Extbase\Persistence\Repository;
  */
 class BackendUserGroupRepository extends Repository
 {
-    /**
-     * @var array Default order is by title ascending
-     */
     protected $defaultOrderings = [
         'title' => QueryInterface::ORDER_ASCENDING,
     ];
diff --git a/typo3/sysext/core/Classes/Utility/ClassNamingUtility.php b/typo3/sysext/core/Classes/Utility/ClassNamingUtility.php
index 3d45889abf45..a377a52848f0 100644
--- a/typo3/sysext/core/Classes/Utility/ClassNamingUtility.php
+++ b/typo3/sysext/core/Classes/Utility/ClassNamingUtility.php
@@ -17,6 +17,8 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Core\Utility;
 
+use TYPO3\CMS\Extbase\Persistence\RepositoryInterface;
+
 /**
  * Several functions related to naming and conversions of names
  * such as translation between Repository and Model names or
@@ -42,6 +44,10 @@ class ClassNamingUtility
      * Translates a repository name to an appropriate model name
      * e.g. Tx_Extbase_Domain_Repository_FooRepository to Tx_Extbase_Domain_Model_Foo
      * or \TYPO3\CMS\Extbase\Domain\Repository\FooRepository to \TYPO3\CMS\Extbase\Domain\Model\Foo
+     *
+     * @param class-string<RepositoryInterface> $repositoryName
+     *
+     * @return class-string
      */
     public static function translateRepositoryNameToModelName(string $repositoryName): string
     {
diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial/Classes/Domain/Repository/ContentRepository.php b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial/Classes/Domain/Repository/ContentRepository.php
index 8f9f20129dca..285b14392610 100644
--- a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial/Classes/Domain/Repository/ContentRepository.php
+++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial/Classes/Domain/Repository/ContentRepository.php
@@ -25,9 +25,6 @@ use TYPO3\CMS\Extbase\Persistence\Repository;
  */
 class ContentRepository extends Repository
 {
-    /**
-     * @var array
-     */
     protected $defaultOrderings = [
         'sorting' => QueryInterface::ORDER_ASCENDING,
     ];
diff --git a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield/Classes/Domain/Repository/ContentRepository.php b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield/Classes/Domain/Repository/ContentRepository.php
index add89b9e4b5d..af630b166d4f 100644
--- a/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield/Classes/Domain/Repository/ContentRepository.php
+++ b/typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_irre_foreignfield/Classes/Domain/Repository/ContentRepository.php
@@ -25,9 +25,6 @@ use TYPO3\CMS\Extbase\Persistence\Repository;
  */
 class ContentRepository extends Repository
 {
-    /**
-     * @var array
-     */
     protected $defaultOrderings = [
         'sorting' => QueryInterface::ORDER_ASCENDING,
     ];
diff --git a/typo3/sysext/extbase/Classes/Persistence/Repository.php b/typo3/sysext/extbase/Classes/Persistence/Repository.php
index 7dc18b79e4f9..1a6e72f99bb4 100644
--- a/typo3/sysext/extbase/Classes/Persistence/Repository.php
+++ b/typo3/sysext/extbase/Classes/Persistence/Repository.php
@@ -32,18 +32,18 @@ class Repository implements RepositoryInterface, SingletonInterface
     protected $persistenceManager;
 
     /**
-     * @var string
+     * @var class-string
      */
     protected $objectType;
 
     /**
-     * @var array
+     * @var array<non-empty-string, QueryInterface::ORDER_*>
      */
     protected $defaultOrderings = [];
 
     /**
      * Override query settings created by extbase natively.
-     * Be careful if using this, see the comment on setDefaultQuerySettings() for more insights.
+     * Be careful if using this, see the comment on `setDefaultQuerySettings()` for more insights.
      *
      * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
      */
@@ -169,7 +169,7 @@ class Repository implements RepositoryInterface, SingletonInterface
      * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
      * )
      *
-     * @param array<string,string> $defaultOrderings The property names to order by
+     * @param array<non-empty-string, QueryInterface::ORDER_*> $defaultOrderings The property names to order by
      */
     public function setDefaultOrderings(array $defaultOrderings)
     {
@@ -212,8 +212,8 @@ class Repository implements RepositoryInterface, SingletonInterface
     /**
      * Dispatches magic methods (findBy[Property]())
      *
-     * @param string $methodName The name of the magic method
-     * @param string $arguments The arguments of the magic method
+     * @param non-empty-string $methodName The name of the magic method
+     * @param array<int, mixed> $arguments The arguments of the magic method
      * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
      * @return mixed
      */
@@ -248,7 +248,7 @@ class Repository implements RepositoryInterface, SingletonInterface
     /**
      * Returns the class name of this class.
      *
-     * @return string Class name of the repository.
+     * @return class-string<RepositoryInterface> Class name of the repository.
      */
     protected function getRepositoryClassName()
     {
-- 
GitLab