Skip to content

Commit 927fc96

Browse files
committed
refactor: fix iterable types in Email
1 parent 590d8eb commit 927fc96

4 files changed

Lines changed: 29 additions & 104 deletions

File tree

‎system/Email/Email.php‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class Email
3030
/**
3131
* Properties from the last successful send.
3232
*
33-
* @var array|null
33+
* @var array<string, mixed>|null
3434
*/
3535
public $archive;
3636

3737
/**
3838
* Properties to be added to the next archive.
3939
*
40-
* @var array
40+
* @var array<string, list<string>|string>
4141
*/
4242
protected $tmpArchive = [];
4343

@@ -298,7 +298,7 @@ class Email
298298
*
299299
* @see Email::printDebugger()
300300
*
301-
* @var array
301+
* @var list<string>
302302
*/
303303
protected $debugMessage = [];
304304

@@ -312,35 +312,42 @@ class Email
312312
/**
313313
* Recipients
314314
*
315-
* @var array|string
315+
* @var list<string>
316316
*/
317317
protected $recipients = [];
318318

319319
/**
320320
* CC Recipients
321321
*
322-
* @var array
322+
* @var list<string>
323323
*/
324324
protected $CCArray = [];
325325

326326
/**
327327
* BCC Recipients
328328
*
329-
* @var array
329+
* @var list<string>
330330
*/
331331
protected $BCCArray = [];
332332

333333
/**
334334
* Message headers
335335
*
336-
* @var array
336+
* @var array<string, string>
337337
*/
338338
protected $headers = [];
339339

340340
/**
341341
* Attachment data
342342
*
343-
* @var array
343+
* @var list<array{
344+
* name: array{0: string, 1: string|null},
345+
* disposition: string,
346+
* type: string,
347+
* content: string,
348+
* multipart: 'mixed'|'related',
349+
* cid?: string,
350+
* }>
344351
*/
345352
protected $attachments = [];
346353

@@ -405,7 +412,7 @@ class Email
405412
protected static $func_overload;
406413

407414
/**
408-
* @param array|\Config\Email|null $config
415+
* @param array<string, mixed>|\Config\Email|null $config
409416
*/
410417
public function __construct($config = null)
411418
{
@@ -419,7 +426,7 @@ public function __construct($config = null)
419426
/**
420427
* Initialize preferences
421428
*
422-
* @param array|\Config\Email|null $config
429+
* @param array<string, mixed>|\Config\Email|null $config
423430
*
424431
* @return $this
425432
*/
@@ -554,7 +561,7 @@ public function setReplyTo($replyto, $name = '')
554561
}
555562

556563
/**
557-
* @param array|string $to
564+
* @param list<string>|string $to
558565
*
559566
* @return $this
560567
*/
@@ -933,7 +940,7 @@ protected function getMimeMessage()
933940
}
934941

935942
/**
936-
* @param array|string $email
943+
* @param list<string>|string $email
937944
*
938945
* @return bool
939946
*/
@@ -972,9 +979,9 @@ public function isValidEmail($email)
972979
}
973980

974981
/**
975-
* @param array|string $email
982+
* @param list<string>|string $email
976983
*
977-
* @return array|string
984+
* @return ($email is array ? list<string> : string)
978985
*/
979986
public function cleanEmail($email)
980987
{
@@ -2121,8 +2128,8 @@ protected function getHostname()
21212128
}
21222129

21232130
/**
2124-
* @param array|string $include List of raw data chunks to include in the output
2125-
* Valid options are: 'headers', 'subject', 'body'
2131+
* @param list<string>|string $include List of raw data chunks to include in the output
2132+
* Valid options are: 'headers', 'subject', 'body'
21262133
*
21272134
* @return string
21282135
*/
@@ -2229,7 +2236,7 @@ protected static function substr($str, $start, $length = null)
22292236
/**
22302237
* Determines the values that should be stored in $archive.
22312238
*
2232-
* @return array The updated archive values
2239+
* @return array<string, mixed> The updated archive values
22332240
*/
22342241
protected function setArchiveValues(): array
22352242
{

‎tests/system/Email/EmailTest.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public function testEmailSendWithClearance($autoClear): void
5858
}
5959
}
6060

61+
/**
62+
* @return iterable<string, list<bool>>
63+
*/
6164
public static function provideEmailSendWithClearance(): iterable
6265
{
6366
return [

‎utils/phpstan-baseline/loader.neon‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 419 errors
1+
# total 402 errors
22

33
includes:
44
- argument.type.neon

‎utils/phpstan-baseline/missingType.iterableValue.neon‎

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 282 errors
1+
# total 265 errors
22

33
parameters:
44
ignoreErrors:
@@ -317,86 +317,6 @@ parameters:
317317
count: 1
318318
path: ../../system/DataConverter/DataConverter.php
319319

320-
-
321-
message: '#^Method CodeIgniter\\Email\\Email\:\:__construct\(\) has parameter \$config with no value type specified in iterable type array\.$#'
322-
count: 1
323-
path: ../../system/Email/Email.php
324-
325-
-
326-
message: '#^Method CodeIgniter\\Email\\Email\:\:cleanEmail\(\) has parameter \$email with no value type specified in iterable type array\.$#'
327-
count: 1
328-
path: ../../system/Email/Email.php
329-
330-
-
331-
message: '#^Method CodeIgniter\\Email\\Email\:\:cleanEmail\(\) return type has no value type specified in iterable type array\.$#'
332-
count: 1
333-
path: ../../system/Email/Email.php
334-
335-
-
336-
message: '#^Method CodeIgniter\\Email\\Email\:\:initialize\(\) has parameter \$config with no value type specified in iterable type array\.$#'
337-
count: 1
338-
path: ../../system/Email/Email.php
339-
340-
-
341-
message: '#^Method CodeIgniter\\Email\\Email\:\:printDebugger\(\) has parameter \$include with no value type specified in iterable type array\.$#'
342-
count: 1
343-
path: ../../system/Email/Email.php
344-
345-
-
346-
message: '#^Method CodeIgniter\\Email\\Email\:\:setArchiveValues\(\) return type has no value type specified in iterable type array\.$#'
347-
count: 1
348-
path: ../../system/Email/Email.php
349-
350-
-
351-
message: '#^Method CodeIgniter\\Email\\Email\:\:setTo\(\) has parameter \$to with no value type specified in iterable type array\.$#'
352-
count: 1
353-
path: ../../system/Email/Email.php
354-
355-
-
356-
message: '#^Method CodeIgniter\\Email\\Email\:\:validateEmail\(\) has parameter \$email with no value type specified in iterable type array\.$#'
357-
count: 1
358-
path: ../../system/Email/Email.php
359-
360-
-
361-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$BCCArray type has no value type specified in iterable type array\.$#'
362-
count: 1
363-
path: ../../system/Email/Email.php
364-
365-
-
366-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$CCArray type has no value type specified in iterable type array\.$#'
367-
count: 1
368-
path: ../../system/Email/Email.php
369-
370-
-
371-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$archive type has no value type specified in iterable type array\.$#'
372-
count: 1
373-
path: ../../system/Email/Email.php
374-
375-
-
376-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$attachments type has no value type specified in iterable type array\.$#'
377-
count: 1
378-
path: ../../system/Email/Email.php
379-
380-
-
381-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$debugMessage type has no value type specified in iterable type array\.$#'
382-
count: 1
383-
path: ../../system/Email/Email.php
384-
385-
-
386-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$headers type has no value type specified in iterable type array\.$#'
387-
count: 1
388-
path: ../../system/Email/Email.php
389-
390-
-
391-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$recipients type has no value type specified in iterable type array\.$#'
392-
count: 1
393-
path: ../../system/Email/Email.php
394-
395-
-
396-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$tmpArchive type has no value type specified in iterable type array\.$#'
397-
count: 1
398-
path: ../../system/Email/Email.php
399-
400320
-
401321
message: '#^Method CodeIgniter\\Encryption\\EncrypterInterface\:\:decrypt\(\) has parameter \$params with no value type specified in iterable type array\.$#'
402322
count: 1
@@ -982,11 +902,6 @@ parameters:
982902
count: 1
983903
path: ../../tests/system/Database/Live/UpdateTest.php
984904

985-
-
986-
message: '#^Method CodeIgniter\\Email\\EmailTest\:\:provideEmailSendWithClearance\(\) return type has no value type specified in iterable type iterable\.$#'
987-
count: 1
988-
path: ../../tests/system/Email/EmailTest.php
989-
990905
-
991906
message: '#^Method CodeIgniter\\Filters\\FiltersTest\:\:provideBeforeExcept\(\) return type has no value type specified in iterable type iterable\.$#'
992907
count: 1

0 commit comments

Comments
 (0)