From 5e1f39fddde426a6c444c8f2c9ae4a74e56860b3 Mon Sep 17 00:00:00 2001
From: Torben Hansen <derhansen@gmail.com>
Date: Thu, 23 Jun 2022 13:00:13 +0200
Subject: [PATCH] [TASK] Use constructor property promotion in ext:felogin
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With this change constructor property promotion is used
in ext:felogin where possible.

Also 2 superfluous overrides of EventDispatcherInterface have
been removed, since the property is already inherited through
ActionController.

Resolves: #97805
Releases: main
Change-Id: I48ac97fe86dc068db023e247039ab38669c868e2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74974
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
---
 .../Configuration/RecoveryConfiguration.php   | 18 +------
 .../Configuration/RedirectConfiguration.php   | 40 +++------------
 .../Classes/Controller/LoginController.php    | 32 ++----------
 .../Controller/PasswordRecoveryController.php | 24 +--------
 .../Repository/FrontendUserRepository.php     | 18 +------
 .../Classes/Redirect/RedirectHandler.php      | 16 +-----
 .../Classes/Redirect/RedirectModeHandler.php  | 40 ++-------------
 .../Classes/Service/RecoveryService.php       | 51 ++-----------------
 8 files changed, 28 insertions(+), 211 deletions(-)

diff --git a/typo3/sysext/felogin/Classes/Configuration/RecoveryConfiguration.php b/typo3/sysext/felogin/Classes/Configuration/RecoveryConfiguration.php
index c71a3dbd0562..f01dcf849039 100644
--- a/typo3/sysext/felogin/Classes/Configuration/RecoveryConfiguration.php
+++ b/typo3/sysext/felogin/Classes/Configuration/RecoveryConfiguration.php
@@ -23,7 +23,6 @@ use Symfony\Component\Mime\Address;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Crypto\Random;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
-use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
 use TYPO3\CMS\Extbase\Security\Cryptography\HashService;
 use TYPO3\CMS\Fluid\View\TemplatePaths;
 
@@ -34,11 +33,6 @@ class RecoveryConfiguration implements LoggerAwareInterface
 {
     use LoggerAwareTrait;
 
-    /**
-     * @var Context
-     */
-    protected $context;
-
     /**
      * @var string
      */
@@ -69,22 +63,12 @@ class RecoveryConfiguration implements LoggerAwareInterface
      */
     protected $timestamp;
 
-    /**
-     * @param Context $context
-     * @param ConfigurationManager $configurationManager
-     * @param Random $random
-     * @param HashService $hashService
-     *
-     * @throws IncompleteConfigurationException
-     * @throws InvalidConfigurationTypeException
-     */
     public function __construct(
-        Context $context,
+        protected Context $context,
         ConfigurationManager $configurationManager,
         Random $random,
         HashService $hashService
     ) {
-        $this->context = $context;
         $this->settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
         $this->forgotHash = $this->getLifeTimeTimestamp() . '|' . $this->generateHash($random, $hashService);
         $this->resolveFromTypoScript();
diff --git a/typo3/sysext/felogin/Classes/Configuration/RedirectConfiguration.php b/typo3/sysext/felogin/Classes/Configuration/RedirectConfiguration.php
index 71f51c3c8100..10a46863e272 100644
--- a/typo3/sysext/felogin/Classes/Configuration/RedirectConfiguration.php
+++ b/typo3/sysext/felogin/Classes/Configuration/RedirectConfiguration.php
@@ -31,39 +31,15 @@ class RedirectConfiguration
      */
     protected $modes;
 
-    /**
-     * @var string
-     */
-    protected $firstMode;
-
-    /**
-     * @var int
-     */
-    protected $pageOnLogin;
-
-    /**
-     * @var string
-     */
-    protected $domains;
-
-    /**
-     * @var int
-     */
-    protected $pageOnLoginError;
-
-    /**
-     * @var int
-     */
-    protected $pageOnLogout;
-
-    public function __construct($mode, string $firstMode, int $pageOnLogin, string $domains, int $pageOnLoginError, int $pageOnLogout)
-    {
+    public function __construct(
+        array|string|null $mode,
+        protected string $firstMode,
+        protected int $pageOnLogin,
+        protected string $domains,
+        protected int $pageOnLoginError,
+        protected int $pageOnLogout
+    ) {
         $this->modes = is_array($mode) ? $mode : GeneralUtility::trimExplode(',', $mode ?? '', true);
-        $this->firstMode = $firstMode;
-        $this->pageOnLogin = $pageOnLogin;
-        $this->domains = $domains;
-        $this->pageOnLoginError = $pageOnLoginError;
-        $this->pageOnLogout = $pageOnLogout;
     }
 
     public function getModes(): array
diff --git a/typo3/sysext/felogin/Classes/Controller/LoginController.php b/typo3/sysext/felogin/Classes/Controller/LoginController.php
index a2b3e8af94ea..9b2627e28afc 100644
--- a/typo3/sysext/felogin/Classes/Controller/LoginController.php
+++ b/typo3/sysext/felogin/Classes/Controller/LoginController.php
@@ -17,7 +17,6 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\FrontendLogin\Controller;
 
-use Psr\EventDispatcher\EventDispatcherInterface;
 use Psr\Http\Message\ResponseInterface;
 use TYPO3\CMS\Core\Authentication\LoginType;
 use TYPO3\CMS\Core\Context\Context;
@@ -54,11 +53,6 @@ class LoginController extends AbstractLoginFormController
      */
     public const MESSAGEKEY_LOGOUT = 'logout';
 
-    /**
-     * @var RedirectHandler
-     */
-    protected $redirectHandler;
-
     /**
      * @var string
      */
@@ -69,26 +63,11 @@ class LoginController extends AbstractLoginFormController
      */
     protected $redirectUrl = '';
 
-    /**
-     * @var ServerRequestHandler
-     */
-    protected $requestHandler;
-
-    /**
-     * @var UserService
-     */
-    protected $userService;
-
     /**
      * @var RedirectConfiguration
      */
     protected $configuration;
 
-    /**
-     * @var EventDispatcherInterface
-     */
-    protected $eventDispatcher;
-
     /**
      * @var UserAspect
      */
@@ -100,15 +79,10 @@ class LoginController extends AbstractLoginFormController
     protected $showCookieWarning = false;
 
     public function __construct(
-        RedirectHandler $redirectHandler,
-        ServerRequestHandler $requestHandler,
-        UserService $userService,
-        EventDispatcherInterface $eventDispatcher
+        protected RedirectHandler $redirectHandler,
+        protected ServerRequestHandler $requestHandler,
+        protected UserService $userService
     ) {
-        $this->redirectHandler = $redirectHandler;
-        $this->requestHandler = $requestHandler;
-        $this->userService = $userService;
-        $this->eventDispatcher = $eventDispatcher;
         $this->userAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
     }
 
diff --git a/typo3/sysext/felogin/Classes/Controller/PasswordRecoveryController.php b/typo3/sysext/felogin/Classes/Controller/PasswordRecoveryController.php
index a12b763f5b6a..68bc66195a5a 100644
--- a/typo3/sysext/felogin/Classes/Controller/PasswordRecoveryController.php
+++ b/typo3/sysext/felogin/Classes/Controller/PasswordRecoveryController.php
@@ -17,7 +17,6 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\FrontendLogin\Controller;
 
-use Psr\EventDispatcher\EventDispatcherInterface;
 use Psr\Http\Message\ResponseInterface;
 use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
@@ -40,29 +39,10 @@ use TYPO3\CMS\FrontendLogin\Service\ValidatorResolverService;
  */
 class PasswordRecoveryController extends AbstractLoginFormController
 {
-    /**
-     * @var RecoveryServiceInterface
-     */
-    protected $recoveryService;
-
-    /**
-     * @var FrontendUserRepository
-     */
-    protected $userRepository;
-
-    /**
-     * @var EventDispatcherInterface
-     */
-    protected $eventDispatcher;
-
     public function __construct(
-        EventDispatcherInterface $eventDispatcher,
-        RecoveryServiceInterface $recoveryService,
-        FrontendUserRepository $userRepository
+        protected RecoveryServiceInterface $recoveryService,
+        protected FrontendUserRepository $userRepository
     ) {
-        $this->eventDispatcher = $eventDispatcher;
-        $this->recoveryService = $recoveryService;
-        $this->userRepository = $userRepository;
     }
 
     /**
diff --git a/typo3/sysext/felogin/Classes/Domain/Repository/FrontendUserRepository.php b/typo3/sysext/felogin/Classes/Domain/Repository/FrontendUserRepository.php
index c543cb3bdf92..4048f921a505 100644
--- a/typo3/sysext/felogin/Classes/Domain/Repository/FrontendUserRepository.php
+++ b/typo3/sysext/felogin/Classes/Domain/Repository/FrontendUserRepository.php
@@ -33,23 +33,9 @@ class FrontendUserRepository
      */
     protected $connection;
 
-    /**
-     * @var Context
-     */
-    protected $context;
-
-    /**
-     * @var UserService
-     */
-    protected $userService;
-
-    public function __construct(
-        UserService $userService,
-        Context $context
-    ) {
-        $this->userService = $userService;
+    public function __construct(protected UserService $userService, protected Context $context)
+    {
         $this->connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->getTable());
-        $this->context = $context;
     }
 
     public function getTable(): string
diff --git a/typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php b/typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php
index d16f7488c1d7..3b324109cc39 100644
--- a/typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php
+++ b/typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php
@@ -33,23 +33,11 @@ class RedirectHandler
      */
     protected $userIsLoggedIn = false;
 
-    /**
-     * @var ServerRequestHandler
-     */
-    protected $requestHandler;
-
-    /**
-     * @var RedirectModeHandler
-     */
-    protected $redirectModeHandler;
-
     public function __construct(
-        ServerRequestHandler $requestHandler,
-        RedirectModeHandler $redirectModeHandler,
+        protected ServerRequestHandler $requestHandler,
+        protected RedirectModeHandler $redirectModeHandler,
         Context $context
     ) {
-        $this->requestHandler = $requestHandler;
-        $this->redirectModeHandler = $redirectModeHandler;
         $this->userIsLoggedIn = (bool)$context->getPropertyFromAspect('frontend.user', 'isLoggedIn');
     }
 
diff --git a/typo3/sysext/felogin/Classes/Redirect/RedirectModeHandler.php b/typo3/sysext/felogin/Classes/Redirect/RedirectModeHandler.php
index 4ae81528f246..f25aa394a70f 100644
--- a/typo3/sysext/felogin/Classes/Redirect/RedirectModeHandler.php
+++ b/typo3/sysext/felogin/Classes/Redirect/RedirectModeHandler.php
@@ -37,47 +37,17 @@ class RedirectModeHandler
      */
     protected $redirectUrlValidator;
 
-    /**
-     * @var UriBuilder
-     */
-    protected $uriBuilder;
-
-    /**
-     * @var ServerRequestHandler
-     */
-    protected $serverRequestHandler;
-
-    /**
-     * @var UserService
-     */
-    private $userService;
-
-    /**
-     * @var FrontendUserRepository
-     */
-    private $frontendUserRepository;
-
-    /**
-     * @var FrontendUserGroupRepository
-     */
-    private $frontendUserGroupRepository;
-
     public function __construct(
-        UriBuilder $uriBuilder,
-        ServerRequestHandler $serverRequestHandler,
-        UserService $userService,
-        FrontendUserRepository $frontendUserRepository,
-        FrontendUserGroupRepository $frontendUserGroupRepository
+        protected UriBuilder $uriBuilder,
+        protected ServerRequestHandler $serverRequestHandler,
+        private UserService $userService,
+        private FrontendUserRepository $frontendUserRepository,
+        private FrontendUserGroupRepository $frontendUserGroupRepository
     ) {
-        $this->uriBuilder = $uriBuilder;
         $this->redirectUrlValidator = GeneralUtility::makeInstance(
             RedirectUrlValidator::class,
             GeneralUtility::makeInstance(SiteFinder::class)
         );
-        $this->serverRequestHandler = $serverRequestHandler;
-        $this->userService = $userService;
-        $this->frontendUserRepository = $frontendUserRepository;
-        $this->frontendUserGroupRepository = $frontendUserGroupRepository;
     }
 
     /**
diff --git a/typo3/sysext/felogin/Classes/Service/RecoveryService.php b/typo3/sysext/felogin/Classes/Service/RecoveryService.php
index e26877fd7409..348088d4c549 100644
--- a/typo3/sysext/felogin/Classes/Service/RecoveryService.php
+++ b/typo3/sysext/felogin/Classes/Service/RecoveryService.php
@@ -26,7 +26,6 @@ use TYPO3\CMS\Core\Mail\FluidEmail;
 use TYPO3\CMS\Core\Mail\Mailer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
-use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
 use TYPO3\CMS\FrontendLogin\Configuration\IncompleteConfigurationException;
@@ -39,60 +38,20 @@ use TYPO3\CMS\FrontendLogin\Event\SendRecoveryEmailEvent;
  */
 class RecoveryService implements RecoveryServiceInterface
 {
-    /**
-     * @var RecoveryConfiguration
-     */
-    protected $recoveryConfiguration;
-
-    /**
-     * @var EventDispatcherInterface
-     */
-    protected $eventDispatcher;
-
-    /**
-     * @var Mailer
-     */
-    protected $mailer;
-
     /**
      * @var array
      */
     protected $settings;
 
-    /**
-     * @var UriBuilder
-     */
-    protected $uriBuilder;
-
-    /**
-     * @var FrontendUserRepository
-     */
-    protected $userRepository;
-
-    /**
-     * @param Mailer $mailer
-     * @param EventDispatcherInterface $eventDispatcher
-     * @param ConfigurationManager $configurationManager
-     * @param RecoveryConfiguration $recoveryConfiguration
-     * @param UriBuilder $uriBuilder
-     * @param FrontendUserRepository $userRepository
-     *
-     * @throws InvalidConfigurationTypeException
-     */
     public function __construct(
-        Mailer $mailer,
-        EventDispatcherInterface $eventDispatcher,
+        protected Mailer $mailer,
+        protected EventDispatcherInterface $eventDispatcher,
         ConfigurationManager $configurationManager,
-        RecoveryConfiguration $recoveryConfiguration,
-        UriBuilder $uriBuilder,
-        FrontendUserRepository $userRepository
+        protected RecoveryConfiguration $recoveryConfiguration,
+        protected UriBuilder $uriBuilder,
+        protected FrontendUserRepository $userRepository
     ) {
-        $this->mailer = $mailer;
-        $this->eventDispatcher = $eventDispatcher;
         $this->settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
-        $this->recoveryConfiguration = $recoveryConfiguration;
-        $this->uriBuilder = $uriBuilder;
-        $this->userRepository = $userRepository;
     }
 
     /**
-- 
GitLab