From 927fc96c397d35e910e379d441a6d15340099843 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Mon, 24 Aug 2026 20:42:45 +0800 Subject: [PATCH] refactor: fix iterable types in `Email` --- system/Email/Email.php | 41 +++++---- tests/system/Email/EmailTest.php | 3 + utils/phpstan-baseline/loader.neon | 2 +- .../missingType.iterableValue.neon | 87 +------------------ 4 files changed, 29 insertions(+), 104 deletions(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index 71c68d9e2841..a3d948d9edfd 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -30,14 +30,14 @@ class Email /** * Properties from the last successful send. * - * @var array|null + * @var array|null */ public $archive; /** * Properties to be added to the next archive. * - * @var array + * @var array|string> */ protected $tmpArchive = []; @@ -298,7 +298,7 @@ class Email * * @see Email::printDebugger() * - * @var array + * @var list */ protected $debugMessage = []; @@ -312,35 +312,42 @@ class Email /** * Recipients * - * @var array|string + * @var list */ protected $recipients = []; /** * CC Recipients * - * @var array + * @var list */ protected $CCArray = []; /** * BCC Recipients * - * @var array + * @var list */ protected $BCCArray = []; /** * Message headers * - * @var array + * @var array */ protected $headers = []; /** * Attachment data * - * @var array + * @var list */ protected $attachments = []; @@ -405,7 +412,7 @@ class Email protected static $func_overload; /** - * @param array|\Config\Email|null $config + * @param array|\Config\Email|null $config */ public function __construct($config = null) { @@ -419,7 +426,7 @@ public function __construct($config = null) /** * Initialize preferences * - * @param array|\Config\Email|null $config + * @param array|\Config\Email|null $config * * @return $this */ @@ -554,7 +561,7 @@ public function setReplyTo($replyto, $name = '') } /** - * @param array|string $to + * @param list|string $to * * @return $this */ @@ -933,7 +940,7 @@ protected function getMimeMessage() } /** - * @param array|string $email + * @param list|string $email * * @return bool */ @@ -972,9 +979,9 @@ public function isValidEmail($email) } /** - * @param array|string $email + * @param list|string $email * - * @return array|string + * @return ($email is array ? list : string) */ public function cleanEmail($email) { @@ -2121,8 +2128,8 @@ protected function getHostname() } /** - * @param array|string $include List of raw data chunks to include in the output - * Valid options are: 'headers', 'subject', 'body' + * @param list|string $include List of raw data chunks to include in the output + * Valid options are: 'headers', 'subject', 'body' * * @return string */ @@ -2229,7 +2236,7 @@ protected static function substr($str, $start, $length = null) /** * Determines the values that should be stored in $archive. * - * @return array The updated archive values + * @return array The updated archive values */ protected function setArchiveValues(): array { diff --git a/tests/system/Email/EmailTest.php b/tests/system/Email/EmailTest.php index 319504237f08..fc94686589d1 100644 --- a/tests/system/Email/EmailTest.php +++ b/tests/system/Email/EmailTest.php @@ -58,6 +58,9 @@ public function testEmailSendWithClearance($autoClear): void } } + /** + * @return iterable> + */ public static function provideEmailSendWithClearance(): iterable { return [ diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 61ebc04982b4..a89fc2794871 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 419 errors +# total 402 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index 333eaa92ae2e..469f31dc8c52 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 282 errors +# total 265 errors parameters: ignoreErrors: @@ -317,86 +317,6 @@ parameters: count: 1 path: ../../system/DataConverter/DataConverter.php - - - message: '#^Method CodeIgniter\\Email\\Email\:\:__construct\(\) has parameter \$config with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Method CodeIgniter\\Email\\Email\:\:cleanEmail\(\) has parameter \$email with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Method CodeIgniter\\Email\\Email\:\:cleanEmail\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Method CodeIgniter\\Email\\Email\:\:initialize\(\) has parameter \$config with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Method CodeIgniter\\Email\\Email\:\:printDebugger\(\) has parameter \$include with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Method CodeIgniter\\Email\\Email\:\:setArchiveValues\(\) return type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Method CodeIgniter\\Email\\Email\:\:setTo\(\) has parameter \$to with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Method CodeIgniter\\Email\\Email\:\:validateEmail\(\) has parameter \$email with no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$BCCArray type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$CCArray type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$archive type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$attachments type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$debugMessage type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$headers type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$recipients type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - - - message: '#^Property CodeIgniter\\Email\\Email\:\:\$tmpArchive type has no value type specified in iterable type array\.$#' - count: 1 - path: ../../system/Email/Email.php - - message: '#^Method CodeIgniter\\Encryption\\EncrypterInterface\:\:decrypt\(\) has parameter \$params with no value type specified in iterable type array\.$#' count: 1 @@ -982,11 +902,6 @@ parameters: count: 1 path: ../../tests/system/Database/Live/UpdateTest.php - - - message: '#^Method CodeIgniter\\Email\\EmailTest\:\:provideEmailSendWithClearance\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/Email/EmailTest.php - - message: '#^Method CodeIgniter\\Filters\\FiltersTest\:\:provideBeforeExcept\(\) return type has no value type specified in iterable type iterable\.$#' count: 1