From 35f220c34f7ca9a5100845aafa1fc654eb748e4c Mon Sep 17 00:00:00 2001
From: Alexander Schnitzler <git@alexanderschnitzler.de>
Date: Sat, 26 Sep 2020 19:35:42 +0200
Subject: [PATCH] [TASK] Fix phpstan checkFunctionArgumentTypes errors in
 ext:felogin

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: #92165
Releases: master, 10.4
Change-Id: I1d6cfbbeb233922d1021a853087261ff91abb8be
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65913
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 .../felogin/Classes/Controller/PasswordRecoveryController.php | 3 ++-
 typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php     | 4 +++-
 .../felogin/Classes/Validation/RedirectUrlValidator.php       | 4 ++--
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/typo3/sysext/felogin/Classes/Controller/PasswordRecoveryController.php b/typo3/sysext/felogin/Classes/Controller/PasswordRecoveryController.php
index e145f4567686..123c70dcbd28 100644
--- a/typo3/sysext/felogin/Classes/Controller/PasswordRecoveryController.php
+++ b/typo3/sysext/felogin/Classes/Controller/PasswordRecoveryController.php
@@ -108,6 +108,7 @@ class PasswordRecoveryController extends AbstractLoginFormController
     protected function validateIfHashHasExpired(): void
     {
         $hash = $this->request->hasArgument('hash') ? $this->request->getArgument('hash') : '';
+        $hash = is_string($hash) ? $hash : '';
 
         if (!$this->hasValidHash($hash)) {
             $this->redirect('recovery', 'PasswordRecovery', 'felogin');
@@ -288,7 +289,7 @@ class PasswordRecoveryController extends AbstractLoginFormController
             $hashedPassword = $event->getHashedPassword();
             if ($event->isPropagationStopped()) {
                 $requestResult = $this->request->getOriginalRequestMappingResults();
-                $requestResult->addError(new Error($event->getErrorMessage(), 1562846833));
+                $requestResult->addError(new Error($event->getErrorMessage() ?? '', 1562846833));
                 $this->request->setOriginalRequestMappingResults($requestResult);
 
                 $this->forward(
diff --git a/typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php b/typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php
index fc51cc170cb4..035691f0781e 100644
--- a/typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php
+++ b/typo3/sysext/felogin/Classes/Redirect/RedirectHandler.php
@@ -158,7 +158,9 @@ class RedirectHandler
         }
 
         // Remove empty values, but keep "0" as value (that's why "strlen" is used as second parameter)
-        $redirectUrlList = array_filter($redirectUrlList, 'strlen');
+        $redirectUrlList = array_filter($redirectUrlList, static function (string $value): bool {
+            return strlen($value) > 0;
+        });
 
         return $redirectFirstMethod
             ? array_shift($redirectUrlList)
diff --git a/typo3/sysext/felogin/Classes/Validation/RedirectUrlValidator.php b/typo3/sysext/felogin/Classes/Validation/RedirectUrlValidator.php
index 1e548c72c659..900f9af17e34 100644
--- a/typo3/sysext/felogin/Classes/Validation/RedirectUrlValidator.php
+++ b/typo3/sysext/felogin/Classes/Validation/RedirectUrlValidator.php
@@ -82,8 +82,8 @@ class RedirectUrlValidator implements LoggerAwareInterface
      */
     protected function isInCurrentDomain(string $url): bool
     {
-        $urlWithoutSchema = preg_replace('#^https?://#', '', $url);
-        $siteUrlWithoutSchema = preg_replace('#^https?://#', '', GeneralUtility::getIndpEnv('TYPO3_SITE_URL'));
+        $urlWithoutSchema = preg_replace('#^https?://#', '', $url) ?? '';
+        $siteUrlWithoutSchema = preg_replace('#^https?://#', '', GeneralUtility::getIndpEnv('TYPO3_SITE_URL')) ?? '';
         return strpos($urlWithoutSchema . '/', GeneralUtility::getIndpEnv('HTTP_HOST') . '/') === 0
             && strpos($urlWithoutSchema, $siteUrlWithoutSchema) === 0;
     }
-- 
GitLab