1515 */
1616abstract class AbstractMail {
1717
18- private $ swapMethods = [
18+ private array $ swapMethods = [
1919 'to ' => 'addAddress ' ,
2020 'cc ' => 'addCC ' ,
2121 'bcc ' => 'addBCC ' ,
@@ -28,56 +28,56 @@ abstract class AbstractMail {
2828 *
2929 * @var array
3030 */
31- public $ from = [];
31+ public array $ from = [];
3232
3333 /**
3434 * The "to" recipients of the message.
3535 *
3636 * @var array
3737 */
38- public $ to = [];
38+ public array $ to = [];
3939
4040 /**
4141 * The "cc" recipients of the message.
4242 *
4343 * @var array
4444 */
45- public $ cc = [];
45+ public array $ cc = [];
4646
4747 /**
4848 * The "bcc" recipients of the message.
4949 *
5050 * @var array
5151 */
52- public $ bcc = [];
52+ public array $ bcc = [];
5353
5454 /**
5555 * The "reply to" recipients of the message.
5656 *
5757 * @var array
5858 */
59- public $ replyTo = [];
59+ public array $ replyTo = [];
6060
6161 /**
6262 * The subject of the message.
6363 *
6464 * @var string
6565 */
66- public $ subject ;
66+ public string $ subject ;
6767
6868 /**
6969 * The attachments for the message.
7070 *
7171 * @var array
7272 */
73- public $ attachments = [];
73+ public array $ attachments = [];
7474
7575 /**
7676 * The raw attachments for the message.
7777 *
7878 * @var array
7979 */
80- public $ rawAttachments = [];
80+ public array $ rawAttachments = [];
8181
8282 /**
8383 * The callback for the message.
@@ -93,7 +93,7 @@ abstract class AbstractMail {
9393 * @param string|null $name
9494 * @return $this
9595 */
96- public function from ($ address , $ name = null ) {
96+ public function from ($ address , $ name = null ): self {
9797 return $ this ->setAddress ($ address , $ name ??$ address , 'from ' );
9898 }
9999
@@ -104,7 +104,7 @@ public function from($address, $name = null) {
104104 * @param string|null $name
105105 * @return $this
106106 */
107- public function to ($ address , $ name = null ) {
107+ public function to ($ address , $ name = null ): self {
108108 return $ this ->setAddress ($ address , $ name ??$ address , 'to ' );
109109 }
110110
@@ -115,7 +115,7 @@ public function to($address, $name = null) {
115115 * @param string|null $name
116116 * @return $this
117117 */
118- public function cc ($ address , $ name = null ) {
118+ public function cc ($ address , $ name = null ): self {
119119 return $ this ->setAddress ($ address , $ name ??$ address , 'cc ' );
120120 }
121121
@@ -126,7 +126,7 @@ public function cc($address, $name = null) {
126126 * @param string|null $name
127127 * @return $this
128128 */
129- public function bcc ($ address , $ name = null ) {
129+ public function bcc ($ address , $ name = null ): self {
130130 return $ this ->setAddress ($ address , $ name ??$ address , 'bcc ' );
131131 }
132132
@@ -137,7 +137,7 @@ public function bcc($address, $name = null) {
137137 * @param string|null $name
138138 * @return $this
139139 */
140- public function replyTo ($ address , $ name = null ) {
140+ public function replyTo ($ address , $ name = null ): self {
141141 return $ this ->setAddress ($ address , $ name ??$ address , 'replyTo ' );
142142 }
143143
@@ -148,7 +148,7 @@ public function replyTo($address, $name = null) {
148148 * @param array $options
149149 * @return $this
150150 */
151- public function attachFile ($ file , array $ options = []) {
151+ public function attachFile ($ file , array $ options = []): self {
152152 $ this ->attachments [] = compact ('file ' , 'options ' );
153153 return $ this ;
154154 }
@@ -161,7 +161,7 @@ public function attachFile($file, array $options = []) {
161161 * @param array $options
162162 * @return $this
163163 */
164- public function attachData ($ data , $ name , array $ options = []) {
164+ public function attachData ($ data , $ name , array $ options = []): self {
165165 $ this ->rawAttachments [] = compact ('data ' , 'name ' , 'options ' );
166166 return $ this ;
167167 }
@@ -184,7 +184,7 @@ protected function buildRowAttachments(PHPMailer $mailer) {
184184 }
185185 }
186186
187- public function getSubject () {
187+ public function getSubject (): string {
188188 return $ this ->subject ?? \get_class ();
189189 }
190190
@@ -196,7 +196,7 @@ public function getSubject() {
196196 * @param string $property
197197 * @return $this
198198 */
199- protected function setAddress ($ address , $ name = null , $ property = 'to ' ) {
199+ protected function setAddress ($ address , $ name = null , $ property = 'to ' ): self {
200200 if (\is_object ($ address )) {
201201 $ address = [
202202 $ address
@@ -257,7 +257,7 @@ public function __construct() {
257257 * Define the message body
258258 * To override
259259 */
260- abstract public function body ();
260+ abstract public function body (): string ;
261261
262262 /**
263263 * Initialize the mail, before buiding
@@ -271,7 +271,7 @@ abstract protected function initialize();
271271 */
272272 protected function beforeBuild () {}
273273
274- public function bodyText () {}
274+ public function bodyText ():? string {}
275275
276276 public function build (PHPMailer $ mailer ) {
277277 $ this ->beforeBuild ();
@@ -316,7 +316,7 @@ protected function loadView($viewName, $pData = NULL) {
316316 return $ this ->view ->render ($ viewName , TRUE );
317317 }
318318
319- public function hasRecipients () {
319+ public function hasRecipients (): bool {
320320 $ res = 0 ;
321321 if (\is_array ($ this ->to )) {
322322 $ res += \sizeof ($ this ->to );
@@ -330,12 +330,12 @@ public function hasRecipients() {
330330 return $ res > 0 ;
331331 }
332332
333- private function getMailerDir () {
333+ private function getMailerDir (): string {
334334 $ rc = new \ReflectionClass (\get_class ($ this ));
335335 return \dirname ($ rc ->getFileName ()) . DIRECTORY_SEPARATOR ;
336336 }
337337
338- public function getAttachmentsDir () {
338+ public function getAttachmentsDir (): string {
339339 return $ this ->getMailerDir () . 'attachments ' . DIRECTORY_SEPARATOR ;
340340 }
341341}
0 commit comments