From f97396c7c89f8bf0a9b13d2f2c1fd1ad5b287437 Mon Sep 17 00:00:00 2001
From: Daniel Goerz <daniel.goerz@posteo.de>
Date: Sat, 26 Sep 2020 17:23:22 +0200
Subject: [PATCH] [TASK] Fix phpstan checkFunctionArgumentTypes errors in
 ext:redirects

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: #92174
Releases: master, 10.4
Change-Id: I1a5421b844c36796dca1336c453ff0333295c320
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65903
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
---
 .../redirects/Classes/Controller/ManagementController.php      | 2 +-
 .../redirects/Classes/Hooks/DataHandlerSlugUpdateHook.php      | 2 +-
 typo3/sysext/redirects/Classes/Service/RedirectService.php     | 2 +-
 typo3/sysext/redirects/Classes/Service/SlugService.php         | 3 +++
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/typo3/sysext/redirects/Classes/Controller/ManagementController.php b/typo3/sysext/redirects/Classes/Controller/ManagementController.php
index 90b9502cc0a6..fcfa1e7d243f 100644
--- a/typo3/sysext/redirects/Classes/Controller/ManagementController.php
+++ b/typo3/sysext/redirects/Classes/Controller/ManagementController.php
@@ -86,7 +86,7 @@ class ManagementController
         $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'overview';
         $this->initializeView($action);
 
-        $result = call_user_func_array([$this, $action . 'Action'], [$request]);
+        $result = $this->{$action . 'Action'}($request);
         if ($result instanceof ResponseInterface) {
             return $result;
         }
diff --git a/typo3/sysext/redirects/Classes/Hooks/DataHandlerSlugUpdateHook.php b/typo3/sysext/redirects/Classes/Hooks/DataHandlerSlugUpdateHook.php
index 76dc8c31fbd3..48749db641f6 100644
--- a/typo3/sysext/redirects/Classes/Hooks/DataHandlerSlugUpdateHook.php
+++ b/typo3/sysext/redirects/Classes/Hooks/DataHandlerSlugUpdateHook.php
@@ -68,7 +68,7 @@ class DataHandlerSlugUpdateHook
             return;
         }
 
-        $record = BackendUtility::getRecordWSOL($table, $id, 'slug');
+        $record = BackendUtility::getRecordWSOL($table, (int)$id, 'slug');
         $this->persistedSlugValues[(int)$id] = $record['slug'];
     }
 
diff --git a/typo3/sysext/redirects/Classes/Service/RedirectService.php b/typo3/sysext/redirects/Classes/Service/RedirectService.php
index 9614ed878c22..3d56cdaa2762 100644
--- a/typo3/sysext/redirects/Classes/Service/RedirectService.php
+++ b/typo3/sysext/redirects/Classes/Service/RedirectService.php
@@ -118,7 +118,7 @@ class RedirectService implements LoggerAwareInterface
             if (!empty($allRedirects[$domainName]['regexp'])) {
                 $allRegexps = array_keys($allRedirects[$domainName]['regexp']);
                 foreach ($allRegexps as $regexp) {
-                    $matchResult = @preg_match($regexp, $path);
+                    $matchResult = @preg_match((string)$regexp, $path);
                     if ($matchResult) {
                         $possibleRedirects += $allRedirects[$domainName]['regexp'][$regexp];
                     } elseif ($matchResult === false) {
diff --git a/typo3/sysext/redirects/Classes/Service/SlugService.php b/typo3/sysext/redirects/Classes/Service/SlugService.php
index ec5c0d8e8f55..b4681b6416a9 100644
--- a/typo3/sysext/redirects/Classes/Service/SlugService.php
+++ b/typo3/sysext/redirects/Classes/Service/SlugService.php
@@ -118,6 +118,9 @@ class SlugService implements LoggerAwareInterface
     public function rebuildSlugsForSlugChange(int $pageId, string $currentSlug, string $newSlug, CorrelationId $correlationId): void
     {
         $currentPageRecord = BackendUtility::getRecord('pages', $pageId);
+        if ($currentPageRecord === null) {
+            return;
+        }
         $this->initializeSettings($pageId);
         if ($this->autoUpdateSlugs || $this->autoCreateRedirects) {
             $this->createCorrelationIds($pageId, $correlationId);
-- 
GitLab