[REF] Add strict types to Utils_Mail::Send
authoreileen <emcnaughton@wikimedia.org>
Tue, 27 Apr 2021 21:25:17 +0000 (09:25 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 27 Apr 2021 21:25:17 +0000 (09:25 +1200)
The function only returns a bool - this makes that explicit / forced and also removes handling for it
to return a PEAR_Error in one place that calls it. A couple of unused params are removed

CRM/Core/BAO/ActionSchedule.php
CRM/Utils/Mail.php

index 68d3721f1f0ea689a8b3e8e311ff6e8f1d6369c0..7cfb0ab076871a8bc51883e81c243c17adf194f5 100644 (file)
@@ -594,7 +594,7 @@ FROM civicrm_action_schedule cas
    * @return array
    *   List of error messages.
    */
-  protected static function sendReminderEmail($tokenRow, $schedule, $toContactID) {
+  protected static function sendReminderEmail($tokenRow, $schedule, $toContactID): array {
     $toEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($toContactID, TRUE);
     if (!$toEmail) {
       return ["email_missing" => "Couldn't find recipient's email address."];
@@ -617,20 +617,20 @@ FROM civicrm_action_schedule cas
       'entity_id' => $schedule->id,
     ];
 
-    if (!$body_html || $tokenRow->context['contact']['preferred_mail_format'] == 'Text' ||
-      $tokenRow->context['contact']['preferred_mail_format'] == 'Both'
+    if (!$body_html || $tokenRow->context['contact']['preferred_mail_format'] === 'Text' ||
+      $tokenRow->context['contact']['preferred_mail_format'] === 'Both'
     ) {
       // render the &amp; entities in text mode, so that the links work
       $mailParams['text'] = str_replace('&amp;', '&', $body_text);
     }
-    if ($body_html && ($tokenRow->context['contact']['preferred_mail_format'] == 'HTML' ||
-        $tokenRow->context['contact']['preferred_mail_format'] == 'Both'
+    if ($body_html && ($tokenRow->context['contact']['preferred_mail_format'] === 'HTML' ||
+        $tokenRow->context['contact']['preferred_mail_format'] === 'Both'
       )
     ) {
       $mailParams['html'] = $body_html;
     }
     $result = CRM_Utils_Mail::send($mailParams);
-    if (!$result || is_a($result, 'PEAR_Error')) {
+    if (!$result) {
       return ['email_fail' => 'Failed to send message'];
     }
 
index 9ab3052d3f57912aee210c35c40a32307ce96b99..9a21b4b9de5ae0977fa962990fca0486c72d453e 100644 (file)
@@ -166,7 +166,7 @@ class CRM_Utils_Mail {
    * @return bool
    *   TRUE if a mail was sent, else FALSE.
    */
-  public static function send(&$params) {
+  public static function send(array &$params): bool {
     $defaultReturnPath = CRM_Core_BAO_MailSettings::defaultReturnPath();
     $includeMessageId = CRM_Core_BAO_MailSettings::includeMessageId();
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
@@ -260,7 +260,7 @@ class CRM_Utils_Mail {
     }
 
     if (!empty($attachments)) {
-      foreach ($attachments as $fileID => $attach) {
+      foreach ($attachments as $attach) {
         $msg->addAttachment(
           $attach['fullPath'],
           $attach['mime_type'],
@@ -277,7 +277,6 @@ class CRM_Utils_Mail {
     $headers = $msg->headers($headers);
 
     $to = [$params['toEmail']];
-    $result = NULL;
     $mailer = \Civi::service('pear_mail');
 
     // CRM-3795, CRM-7355, CRM-7557, CRM-9058, CRM-9887, CRM-12883, CRM-19173 and others ...