@@ -52,12 +52,10 @@ public function __construct()
5252
5353
5454 /**
55- * Sets the sender of the message.
56- * @param string email or format "John Doe" <[email protected] > 57- * @param string
55+ * Sets the sender of the message. Email or format "John Doe" <[email protected] > 5856 * @return static
5957 */
60- public function setFrom ($ email , $ name = NULL )
58+ public function setFrom (string $ email , string $ name = NULL )
6159 {
6260 $ this ->setHeader ('From ' , $ this ->formatEmail ($ email , $ name ));
6361 return $ this ;
@@ -66,21 +64,18 @@ public function setFrom($email, $name = NULL)
6664
6765 /**
6866 * Returns the sender of the message.
69- * @return array
7067 */
71- public function getFrom ()
68+ public function getFrom (): array
7269 {
7370 return $ this ->getHeader ('From ' );
7471 }
7572
7673
7774 /**
78- * Adds the reply-to address.
79- * @param string email or format "John Doe" <[email protected] > 80- * @param string
75+ * Adds the reply-to address. Email or format "John Doe" <[email protected] > 8176 * @return static
8277 */
83- public function addReplyTo ($ email , $ name = NULL )
78+ public function addReplyTo (string $ email , string $ name = NULL )
8479 {
8580 $ this ->setHeader ('Reply-To ' , $ this ->formatEmail ($ email , $ name ), TRUE );
8681 return $ this ;
@@ -89,10 +84,9 @@ public function addReplyTo($email, $name = NULL)
8984
9085 /**
9186 * Sets the subject of the message.
92- * @param string
9387 * @return static
9488 */
95- public function setSubject ($ subject )
89+ public function setSubject (string $ subject )
9690 {
9791 $ this ->setHeader ('Subject ' , $ subject );
9892 return $ this ;
@@ -101,47 +95,40 @@ public function setSubject($subject)
10195
10296 /**
10397 * Returns the subject of the message.
104- * @return string|NULL
10598 */
106- public function getSubject ()
99+ public function getSubject (): ? string
107100 {
108101 return $ this ->getHeader ('Subject ' );
109102 }
110103
111104
112105 /**
113- * Adds email recipient.
114- * @param string email or format "John Doe" <[email protected] > 115- * @param string
106+ * Adds email recipient. Email or format "John Doe" <[email protected] > 116107 * @return static
117108 */
118- public function addTo ($ email , $ name = NULL ) // addRecipient()
109+ public function addTo (string $ email , string $ name = NULL ) // addRecipient()
119110 {
120111 $ this ->setHeader ('To ' , $ this ->formatEmail ($ email , $ name ), TRUE );
121112 return $ this ;
122113 }
123114
124115
125116 /**
126- * Adds carbon copy email recipient.
127- * @param string email or format "John Doe" <[email protected] > 128- * @param string
117+ * Adds carbon copy email recipient. Email or format "John Doe" <[email protected] > 129118 * @return static
130119 */
131- public function addCc ($ email , $ name = NULL )
120+ public function addCc (string $ email , string $ name = NULL )
132121 {
133122 $ this ->setHeader ('Cc ' , $ this ->formatEmail ($ email , $ name ), TRUE );
134123 return $ this ;
135124 }
136125
137126
138127 /**
139- * Adds blind carbon copy email recipient.
140- * @param string email or format "John Doe" <[email protected] > 141- * @param string
128+ * Adds blind carbon copy email recipient. Email or format "John Doe" <[email protected] > 142129 * @return static
143130 */
144- public function addBcc ($ email , $ name = NULL )
131+ public function addBcc (string $ email , string $ name = NULL )
145132 {
146133 $ this ->setHeader ('Bcc ' , $ this ->formatEmail ($ email , $ name ), TRUE );
147134 return $ this ;
@@ -150,11 +137,8 @@ public function addBcc($email, $name = NULL)
150137
151138 /**
152139 * Formats recipient email.
153- * @param string
154- * @param string|NULL
155- * @return array
156140 */
157- private function formatEmail ($ email , $ name)
141+ private function formatEmail (string $ email , string $ name = NULL ): array
158142 {
159143 if (!$ name && preg_match ('#^(.+) +<(.*)>\z# ' , $ email , $ matches )) {
160144 return [$ matches [2 ] => $ matches [1 ]];
@@ -166,10 +150,9 @@ private function formatEmail($email, $name)
166150
167151 /**
168152 * Sets the Return-Path header of the message.
169- * @param string email
170153 * @return static
171154 */
172- public function setReturnPath ($ email )
155+ public function setReturnPath (string $ email )
173156 {
174157 $ this ->setHeader ('Return-Path ' , $ email );
175158 return $ this ;
@@ -178,20 +161,18 @@ public function setReturnPath($email)
178161
179162 /**
180163 * Returns the Return-Path header.
181- * @return string
182164 */
183- public function getReturnPath ()
165+ public function getReturnPath (): string
184166 {
185167 return $ this ->getHeader ('Return-Path ' );
186168 }
187169
188170
189171 /**
190172 * Sets email priority.
191- * @param int
192173 * @return static
193174 */
194- public function setPriority ($ priority )
175+ public function setPriority (int $ priority )
195176 {
196177 $ this ->setHeader ('X-Priority ' , (int ) $ priority );
197178 return $ this ;
@@ -200,21 +181,18 @@ public function setPriority($priority)
200181
201182 /**
202183 * Returns email priority.
203- * @return int
204184 */
205- public function getPriority ()
185+ public function getPriority (): int
206186 {
207187 return $ this ->getHeader ('X-Priority ' );
208188 }
209189
210190
211191 /**
212192 * Sets HTML body.
213- * @param string
214- * @param string
215193 * @return static
216194 */
217- public function setHtmlBody ($ html , $ basePath = NULL )
195+ public function setHtmlBody (string $ html , string $ basePath = NULL )
218196 {
219197 $ html = (string ) $ html ;
220198
@@ -262,22 +240,17 @@ public function setHtmlBody($html, $basePath = NULL)
262240
263241 /**
264242 * Gets HTML body.
265- * @return string
266243 */
267- public function getHtmlBody ()
244+ public function getHtmlBody (): string
268245 {
269246 return $ this ->htmlBody ;
270247 }
271248
272249
273250 /**
274251 * Adds embedded file.
275- * @param string
276- * @param string
277- * @param string
278- * @return MimePart
279252 */
280- public function addEmbeddedFile ($ file , $ content = NULL , $ contentType = NULL )
253+ public function addEmbeddedFile (string $ file , string $ content = NULL , string $ contentType = NULL ): MimePart
281254 {
282255 return $ this ->inlines [$ file ] = $ this ->createAttachment ($ file , $ content , $ contentType , 'inline ' )
283256 ->setHeader ('Content-ID ' , $ this ->getRandomId ());
@@ -286,7 +259,6 @@ public function addEmbeddedFile($file, $content = NULL, $contentType = NULL)
286259
287260 /**
288261 * Adds inlined Mime Part.
289- * @param MimePart
290262 * @return static
291263 */
292264 public function addInlinePart (MimePart $ part )
@@ -298,12 +270,8 @@ public function addInlinePart(MimePart $part)
298270
299271 /**
300272 * Adds attachment.
301- * @param string
302- * @param string
303- * @param string
304- * @return MimePart
305273 */
306- public function addAttachment ($ file , $ content = NULL , $ contentType = NULL )
274+ public function addAttachment (string $ file , string $ content = NULL , string $ contentType = NULL ): MimePart
307275 {
308276 return $ this ->attachments [] = $ this ->createAttachment ($ file , $ content , $ contentType , 'attachment ' );
309277 }
@@ -313,21 +281,16 @@ public function addAttachment($file, $content = NULL, $contentType = NULL)
313281 * Gets all email attachments.
314282 * @return MimePart[]
315283 */
316- public function getAttachments ()
284+ public function getAttachments (): array
317285 {
318286 return $ this ->attachments ;
319287 }
320288
321289
322290 /**
323291 * Creates file MIME part.
324- * @param string
325- * @param string|NULL
326- * @param string|NULL
327- * @param string
328- * @return MimePart
329292 */
330- private function createAttachment ($ file , $ content, $ contentType, $ disposition )
293+ private function createAttachment (string $ file , string $ content = NULL , string $ contentType = NULL , string $ disposition ): MimePart
331294 {
332295 $ part = new MimePart ;
333296 if ($ content === NULL ) {
@@ -351,9 +314,8 @@ private function createAttachment($file, $content, $contentType, $disposition)
351314
352315 /**
353316 * Returns encoded message.
354- * @return string
355317 */
356- public function generateMessage ()
318+ public function generateMessage (): string
357319 {
358320 return $ this ->build ()->getEncodedMessage ();
359321 }
@@ -409,10 +371,8 @@ protected function build()
409371
410372 /**
411373 * Builds text content.
412- * @param string
413- * @return string
414374 */
415- protected function buildText ($ html )
375+ protected function buildText (string $ html ): string
416376 {
417377 $ text = Strings::replace ($ html , [
418378 '#<(style|script|head).*</ \\1>#Uis ' => '' ,
@@ -427,8 +387,7 @@ protected function buildText($html)
427387 }
428388
429389
430- /** @return string */
431- private function getRandomId ()
390+ private function getRandomId (): string
432391 {
433392 return '< ' . Nette \Utils \Random::generate () . '@ '
434393 . preg_replace ('#[^\w.-]+# ' , '' , $ _SERVER ['HTTP_HOST ' ] ?? php_uname ('n ' ))
0 commit comments