Skip to content

Commit 6b8e12a

Browse files
authored
refactor: fix iterable types in Email (#10487)
1 parent e4b057e commit 6b8e12a

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 185 errors
1+
# total 168 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 127 errors
1+
# total 110 errors
22

33
parameters:
44
ignoreErrors:
@@ -82,86 +82,6 @@ parameters:
8282
count: 1
8383
path: ../../system/DataConverter/DataConverter.php
8484

85-
-
86-
message: '#^Method CodeIgniter\\Email\\Email\:\:__construct\(\) has parameter \$config with no value type specified in iterable type array\.$#'
87-
count: 1
88-
path: ../../system/Email/Email.php
89-
90-
-
91-
message: '#^Method CodeIgniter\\Email\\Email\:\:cleanEmail\(\) has parameter \$email with no value type specified in iterable type array\.$#'
92-
count: 1
93-
path: ../../system/Email/Email.php
94-
95-
-
96-
message: '#^Method CodeIgniter\\Email\\Email\:\:cleanEmail\(\) return type has no value type specified in iterable type array\.$#'
97-
count: 1
98-
path: ../../system/Email/Email.php
99-
100-
-
101-
message: '#^Method CodeIgniter\\Email\\Email\:\:initialize\(\) has parameter \$config with no value type specified in iterable type array\.$#'
102-
count: 1
103-
path: ../../system/Email/Email.php
104-
105-
-
106-
message: '#^Method CodeIgniter\\Email\\Email\:\:printDebugger\(\) has parameter \$include with no value type specified in iterable type array\.$#'
107-
count: 1
108-
path: ../../system/Email/Email.php
109-
110-
-
111-
message: '#^Method CodeIgniter\\Email\\Email\:\:setArchiveValues\(\) return type has no value type specified in iterable type array\.$#'
112-
count: 1
113-
path: ../../system/Email/Email.php
114-
115-
-
116-
message: '#^Method CodeIgniter\\Email\\Email\:\:setTo\(\) has parameter \$to with no value type specified in iterable type array\.$#'
117-
count: 1
118-
path: ../../system/Email/Email.php
119-
120-
-
121-
message: '#^Method CodeIgniter\\Email\\Email\:\:validateEmail\(\) has parameter \$email with no value type specified in iterable type array\.$#'
122-
count: 1
123-
path: ../../system/Email/Email.php
124-
125-
-
126-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$BCCArray type has no value type specified in iterable type array\.$#'
127-
count: 1
128-
path: ../../system/Email/Email.php
129-
130-
-
131-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$CCArray type has no value type specified in iterable type array\.$#'
132-
count: 1
133-
path: ../../system/Email/Email.php
134-
135-
-
136-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$archive type has no value type specified in iterable type array\.$#'
137-
count: 1
138-
path: ../../system/Email/Email.php
139-
140-
-
141-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$attachments type has no value type specified in iterable type array\.$#'
142-
count: 1
143-
path: ../../system/Email/Email.php
144-
145-
-
146-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$debugMessage type has no value type specified in iterable type array\.$#'
147-
count: 1
148-
path: ../../system/Email/Email.php
149-
150-
-
151-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$headers type has no value type specified in iterable type array\.$#'
152-
count: 1
153-
path: ../../system/Email/Email.php
154-
155-
-
156-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$recipients type has no value type specified in iterable type array\.$#'
157-
count: 1
158-
path: ../../system/Email/Email.php
159-
160-
-
161-
message: '#^Property CodeIgniter\\Email\\Email\:\:\$tmpArchive type has no value type specified in iterable type array\.$#'
162-
count: 1
163-
path: ../../system/Email/Email.php
164-
16585
-
16686
message: '#^Method CodeIgniter\\Exceptions\\PageNotFoundException\:\:lang\(\) has parameter \$args with no value type specified in iterable type array\.$#'
16787
count: 1
@@ -502,11 +422,6 @@ parameters:
502422
count: 1
503423
path: ../../tests/system/Database/Live/UpdateTest.php
504424

505-
-
506-
message: '#^Method CodeIgniter\\Email\\EmailTest\:\:provideEmailSendWithClearance\(\) return type has no value type specified in iterable type iterable\.$#'
507-
count: 1
508-
path: ../../tests/system/Email/EmailTest.php
509-
510425
-
511426
message: '#^Method CodeIgniter\\I18n\\TimeLegacyTest\:\:provideToStringDoesNotDependOnLocale\(\) return type has no value type specified in iterable type iterable\.$#'
512427
count: 1

0 commit comments

Comments
 (0)