From 4a574c76fbae56105ecfbd80b0f0cdeb695d5edd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BCrk?= <stefan@buerk.tech>
Date: Sun, 23 Jun 2024 17:36:00 +0200
Subject: [PATCH] [TASK] Avoid implicitly nullable class method parameter in
 `EXT:workspaces`
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

With PHP 8.4 marking method parameter implicitly nullable
is deprecated and will emit a `E_DEPRECATED` warning. One
recommended way to resolve this, is making it explicitly
nullable using the `?` nullable operator. [1]

This prepares the way towards PHP 8.4 compatibility and
unifies towards using `?` nullable operator over union
null type when possible.

[1] https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated

Resolves: #104185
Releases: main, 12.4, 11.5
Change-Id: I12462595d622efa1bbe2a479f159d68a984bda23
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84869
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Garvin Hicking <gh@faktor-e.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Garvin Hicking <gh@faktor-e.de>
---
 .../workspaces/Classes/Controller/ReviewController.php      | 2 +-
 .../workspaces/Classes/Domain/Model/DatabaseRecord.php      | 2 +-
 .../sysext/workspaces/Classes/Domain/Record/StageRecord.php | 4 ++--
 .../workspaces/Classes/Domain/Record/WorkspaceRecord.php    | 2 +-
 .../workspaces/Classes/Middleware/WorkspacePreview.php      | 2 +-
 .../sysext/workspaces/Classes/Preview/PreviewUriBuilder.php | 6 +++---
 6 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/typo3/sysext/workspaces/Classes/Controller/ReviewController.php b/typo3/sysext/workspaces/Classes/Controller/ReviewController.php
index 1a2300437205..4e430362c048 100644
--- a/typo3/sysext/workspaces/Classes/Controller/ReviewController.php
+++ b/typo3/sysext/workspaces/Classes/Controller/ReviewController.php
@@ -280,7 +280,7 @@ class ReviewController
      * @param int $workspaceId
      * @return string
      */
-    protected function getModuleUri(int $workspaceId = null): string
+    protected function getModuleUri(?int $workspaceId = null): string
     {
         $parameters = [
             'id' => $this->pageId,
diff --git a/typo3/sysext/workspaces/Classes/Domain/Model/DatabaseRecord.php b/typo3/sysext/workspaces/Classes/Domain/Model/DatabaseRecord.php
index aa5ae23f8fe0..b53049ecaa96 100644
--- a/typo3/sysext/workspaces/Classes/Domain/Model/DatabaseRecord.php
+++ b/typo3/sysext/workspaces/Classes/Domain/Model/DatabaseRecord.php
@@ -67,7 +67,7 @@ class DatabaseRecord
      * @param int $uid Id of the database record row
      * @param array|null $row The relevant database record row
      */
-    public function __construct($table, $uid, array $row = null)
+    public function __construct($table, $uid, ?array $row = null)
     {
         $this->setTable($table);
         $this->setUid($uid);
diff --git a/typo3/sysext/workspaces/Classes/Domain/Record/StageRecord.php b/typo3/sysext/workspaces/Classes/Domain/Record/StageRecord.php
index 55b989e7f6ac..807379a934fa 100644
--- a/typo3/sysext/workspaces/Classes/Domain/Record/StageRecord.php
+++ b/typo3/sysext/workspaces/Classes/Domain/Record/StageRecord.php
@@ -57,7 +57,7 @@ class StageRecord extends AbstractRecord
      * @param array $record
      * @return StageRecord|null
      */
-    public static function get($uid, array $record = null)
+    public static function get($uid, ?array $record = null)
     {
         if (empty($record)) {
             $record = static::fetch('sys_workspace_stage', $uid);
@@ -71,7 +71,7 @@ class StageRecord extends AbstractRecord
      * @param array $record
      * @return StageRecord
      */
-    public static function build(WorkspaceRecord $workspace, $uid, array $record = null)
+    public static function build(WorkspaceRecord $workspace, $uid, ?array $record = null)
     {
         if (empty($record)) {
             $record = static::fetch('sys_workspace_stage', $uid);
diff --git a/typo3/sysext/workspaces/Classes/Domain/Record/WorkspaceRecord.php b/typo3/sysext/workspaces/Classes/Domain/Record/WorkspaceRecord.php
index 9f76f3beb794..8c19dbe2afa2 100644
--- a/typo3/sysext/workspaces/Classes/Domain/Record/WorkspaceRecord.php
+++ b/typo3/sysext/workspaces/Classes/Domain/Record/WorkspaceRecord.php
@@ -72,7 +72,7 @@ class WorkspaceRecord extends AbstractRecord
      * @param array $record
      * @return WorkspaceRecord
      */
-    public static function get($uid, array $record = null)
+    public static function get($uid, ?array $record = null)
     {
         if (empty($uid)) {
             $record = [];
diff --git a/typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php b/typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php
index 22ecb45d0c0b..47032255fc36 100644
--- a/typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php
+++ b/typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php
@@ -413,7 +413,7 @@ class WorkspacePreview implements MiddlewareInterface
     /**
      * Register or override the backend user as aspect, as well as the workspace information the user object is holding
      */
-    protected function setBackendUserAspect(Context $context, BackendUserAuthentication $user = null)
+    protected function setBackendUserAspect(Context $context, ?BackendUserAuthentication $user = null)
     {
         $context->setAspect('backend.user', GeneralUtility::makeInstance(UserAspect::class, $user));
         $context->setAspect('workspace', GeneralUtility::makeInstance(WorkspaceAspect::class, $user ? $user->workspace : 0));
diff --git a/typo3/sysext/workspaces/Classes/Preview/PreviewUriBuilder.php b/typo3/sysext/workspaces/Classes/Preview/PreviewUriBuilder.php
index 1b32c33f38f9..0546d589ee8e 100644
--- a/typo3/sysext/workspaces/Classes/Preview/PreviewUriBuilder.php
+++ b/typo3/sysext/workspaces/Classes/Preview/PreviewUriBuilder.php
@@ -148,7 +148,7 @@ class PreviewUriBuilder
      * @param array $versionRecord Optional version record data
      * @return string
      */
-    public function buildUriForElement(string $table, int $uid, array $liveRecord = null, array $versionRecord = null): string
+    public function buildUriForElement(string $table, int $uid, ?array $liveRecord = null, ?array $versionRecord = null): string
     {
         $previewUri = $this->createPreviewUriForElement($table, $uid, $liveRecord, $versionRecord);
         $event = new RetrievedPreviewUrlEvent($table, $uid, $previewUri, [
@@ -161,7 +161,7 @@ class PreviewUriBuilder
         return $previewUri;
     }
 
-    protected function createPreviewUriForElement(string $table, int $uid, array $liveRecord = null, array $versionRecord = null): ?UriInterface
+    protected function createPreviewUriForElement(string $table, int $uid, ?array $liveRecord = null, ?array $versionRecord = null): ?UriInterface
     {
         if ($table === 'pages') {
             return BackendPreviewUriBuilder::create((int)BackendUtility::getLiveVersionIdOfRecord('pages', $uid))
@@ -221,7 +221,7 @@ class PreviewUriBuilder
      * @param int|null $workspaceId Which workspace ID to preview.
      * @return string Returns keyword to use in URL for ADMCMD_prev=, a 32 byte MD5 hash keyword for the URL: "?ADMCMD_prev=[keyword]
      */
-    protected function compilePreviewKeyword(int $ttl = 172800, int $workspaceId = null): string
+    protected function compilePreviewKeyword(int $ttl = 172800, ?int $workspaceId = null): string
     {
         $keyword = md5(StringUtility::getUniqueId());
         GeneralUtility::makeInstance(ConnectionPool::class)
-- 
GitLab