From 1611b32eff78a4233bc92b3f9131387f495340ba Mon Sep 17 00:00:00 2001
From: Oliver Klee <typo3-coding@oliverklee.de>
Date: Sat, 25 Jun 2022 23:08:39 +0200
Subject: [PATCH] [TASK] Improve the comments and type annotations of
 MailUtility
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This helps extensions that rely on the type annotations of that
class for static analysis.

Resolves: #97812
Related: #97377
Releases: 11.5
Change-Id: I0b48f459617e4f4e6c609bdb3abf6f8b465dabd9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74985
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Nikita Hovratov <nikita.h@live.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
---
 Build/phpstan/phpstan-baseline.neon             | 10 ----------
 .../sysext/core/Classes/Utility/MailUtility.php | 17 ++++++++++++++---
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon
index 8167cbc2c196..dc5974dcf55c 100644
--- a/Build/phpstan/phpstan-baseline.neon
+++ b/Build/phpstan/phpstan-baseline.neon
@@ -1825,16 +1825,6 @@ parameters:
 			count: 1
 			path: ../../typo3/sysext/core/Classes/Utility/IpAnonymizationUtility.php
 
-		-
-			message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\MailUtility\\:\\:getSystemFrom\\(\\) should return array but returns null\\.$#"
-			count: 1
-			path: ../../typo3/sysext/core/Classes/Utility/MailUtility.php
-
-		-
-			message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\MailUtility\\:\\:getSystemFromName\\(\\) should return string but returns null\\.$#"
-			count: 1
-			path: ../../typo3/sysext/core/Classes/Utility/MailUtility.php
-
 		-
 			message: "#^Method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\MathUtility\\:\\:calculateWithParentheses\\(\\) should return int but returns string\\.$#"
 			count: 2
diff --git a/typo3/sysext/core/Classes/Utility/MailUtility.php b/typo3/sysext/core/Classes/Utility/MailUtility.php
index 4437546a64e8..57bdf1dadd3f 100644
--- a/typo3/sysext/core/Classes/Utility/MailUtility.php
+++ b/typo3/sysext/core/Classes/Utility/MailUtility.php
@@ -27,7 +27,12 @@ class MailUtility
      *
      * Ready to be passed to $mail->setFrom()
      *
-     * @return array key=Valid email address which can be used as sender, value=Valid name which can be used as a sender. NULL if no address is configured
+     * This method can return three different variants:
+     * 1. An assoc. array: key => Valid email address which can be used as sender; value => Valid name which can be used as a sender
+     * 2. A numeric array with one entry: Valid email address which can be used as sender
+     * 3. Null, if no address is configured
+     *
+     * @return array<string|int, string>|null
      */
     public static function getSystemFrom()
     {
@@ -47,7 +52,7 @@ class MailUtility
      *
      * As configured in Install Tool.
      *
-     * @return string The name (unquoted, unformatted). NULL if none is set
+     * @return string|null The name (unquoted, unformatted). NULL if none is set or an invalid non-string value.
      */
     public static function getSystemFromName()
     {
@@ -90,7 +95,13 @@ class MailUtility
      *
      * Ready to be passed to $mail->setReplyTo()
      *
-     * @return array List of email-addresses. Specifying a realname can be done in the form of "replyToName <replyTo@example.com>".
+     * This method returns a list of email addresses, but depending on the existence of "defaultMailReplyToName"
+     * the array can have a different shape:
+     *
+     * 1. An assoc. array: key => a valid reply-to address which can be used as sender; value => a valid reply-to name which can be used as a sender
+     * 2. A numeric array with one entry: a valid reply-to address which can be used as sender
+     *
+     * @return array<string|int, string>
      */
     public static function getSystemReplyTo(): array
     {
-- 
GitLab