[NFC] Reformat tricksy file CRM_Mailing_BAO_Mailing
authoreileen <emcnaughton@wikimedia.org>
Fri, 5 Apr 2019 06:50:42 +0000 (19:50 +1300)
committerTim Otten <totten@civicrm.org>
Fri, 5 Apr 2019 19:55:05 +0000 (12:55 -0700)
CRM/Mailing/BAO/Mailing.php

index ce320a9b26838963fcd08eff16c6cd3c58962617..a6e37494c442785611d3d54b703ff801b645a70b 100644 (file)
@@ -104,7 +104,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
     //rebuild the recipients
     self::getRecipients($mailingID);
 
-    return civicrm_api3('MailingRecipients', 'getcount', array('mailing_id' => $mailingID));
+    return civicrm_api3('MailingRecipients', 'getcount', ['mailing_id' => $mailingID]);
   }
 
   /**
@@ -125,14 +125,14 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
     $isSMSmode = (!CRM_Utils_System::isNull($mailingObj->sms_provider_id));
 
     $mailingGroup = new CRM_Mailing_DAO_MailingGroup();
-    $recipientsGroup = $excludeSmartGroupIDs = $includeSmartGroupIDs = $priorMailingIDs = array();
+    $recipientsGroup = $excludeSmartGroupIDs = $includeSmartGroupIDs = $priorMailingIDs = [];
     $dao = CRM_Utils_SQL_Select::from('civicrm_mailing_group')
-             ->select('GROUP_CONCAT(entity_id SEPARATOR ",") as group_ids, group_type, entity_table')
-             ->where('mailing_id = #mailing_id AND entity_table RLIKE "^civicrm_(group.*|mailing)$" ')
-             ->groupBy(array('group_type', 'entity_table'))
-             ->param('!groupTableName', CRM_Contact_BAO_Group::getTableName())
-             ->param('#mailing_id', $mailingID)
-             ->execute();
+      ->select('GROUP_CONCAT(entity_id SEPARATOR ",") as group_ids, group_type, entity_table')
+      ->where('mailing_id = #mailing_id AND entity_table RLIKE "^civicrm_(group.*|mailing)$" ')
+      ->groupBy(['group_type', 'entity_table'])
+      ->param('!groupTableName', CRM_Contact_BAO_Group::getTableName())
+      ->param('#mailing_id', $mailingID)
+      ->execute();
     while ($dao->fetch()) {
       if ($dao->entity_table == 'civicrm_mailing') {
         $priorMailingIDs[$dao->group_type] = explode(',', $dao->group_ids);
@@ -145,7 +145,12 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
     // there is no need to proceed further if no mailing group is selected to include recipients,
     // but before return clear the mailing recipients populated earlier since as per current params no group is selected
     if (empty($recipientsGroup['Include']) && empty($priorMailingIDs['Include'])) {
-      CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_mailing_recipients WHERE  mailing_id = %1 ", array(1 => array($mailingID, 'Integer')));
+      CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_mailing_recipients WHERE  mailing_id = %1 ", [
+        1 => [
+          $mailingID,
+          'Integer',
+        ],
+      ]);
       return;
     }
 
@@ -190,7 +195,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         ->select('DISTINCT contact_id')
         ->where('status = "Added" AND group_id IN (#groups)')
         ->param('#groups', $recipientsGroup['Exclude'])
-        ->insertInto($excludeTempTablename, array('contact_id'))
+        ->insertInto($excludeTempTablename, ['contact_id'])
         ->execute();
 
       if (count($excludeSmartGroupIDs)) {
@@ -198,7 +203,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
           ->select('contact_id')
           ->where('group_id IN (#groups)')
           ->param('#groups', $excludeSmartGroupIDs)
-          ->insertIgnoreInto($excludeTempTablename, array('contact_id'))
+          ->insertIgnoreInto($excludeTempTablename, ['contact_id'])
           ->execute();
       }
     }
@@ -207,7 +212,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         ->select('DISTINCT contact_id')
         ->where('mailing_id IN (#mailings)')
         ->param('#mailings', $priorMailingIDs['Exclude'])
-        ->insertIgnoreInto($excludeTempTablename, array('contact_id'))
+        ->insertIgnoreInto($excludeTempTablename, ['contact_id'])
         ->execute();
     }
 
@@ -216,7 +221,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         ->select('DISTINCT contact_id')
         ->where('status = "Removed" AND group_id IN (#groups)')
         ->param('#groups', $recipientsGroup['Base'])
-        ->insertIgnoreInto($excludeTempTablename, array('contact_id'))
+        ->insertIgnoreInto($excludeTempTablename, ['contact_id'])
         ->execute();
     }
 
@@ -230,7 +235,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
     );
 
     if ($isSMSmode) {
-      $criteria = array(
+      $criteria = [
         'is_opt_out' => CRM_Utils_SQL_Select::fragment()->where("$contact.is_opt_out = 0"),
         'is_deceased' => CRM_Utils_SQL_Select::fragment()->where("$contact.is_deceased <> 1"),
         'do_not_sms' => CRM_Utils_SQL_Select::fragment()->where("$contact.do_not_sms = 0"),
@@ -240,11 +245,11 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         'mailing_id' => CRM_Utils_SQL_Select::fragment()->where("mg.mailing_id = #mailingID"),
         'temp_contact_null' => CRM_Utils_SQL_Select::fragment()->where('temp.contact_id IS null'),
         'order_by' => CRM_Utils_SQL_Select::fragment()->orderBy("$entityTable.is_primary"),
-      );
+      ];
     }
     else {
       // Criterias to filter recipients that need to be included
-      $criteria = array(
+      $criteria = [
         'do_not_email' => CRM_Utils_SQL_Select::fragment()->where("$contact.do_not_email = 0"),
         'is_opt_out' => CRM_Utils_SQL_Select::fragment()->where("$contact.is_opt_out = 0"),
         'is_deceased' => CRM_Utils_SQL_Select::fragment()->where("$contact.is_deceased <> 1"),
@@ -255,7 +260,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         'mailing_id' => CRM_Utils_SQL_Select::fragment()->where("mg.mailing_id = #mailingID"),
         'temp_contact_null' => CRM_Utils_SQL_Select::fragment()->where('temp.contact_id IS NULL'),
         'order_by' => CRM_Utils_SQL_Select::fragment()->orderBy($order_by),
-      );
+      ];
     }
 
     // Allow user to alter query responsible to fetch mailing recipients before build,
@@ -273,8 +278,8 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         ->join('temp', " LEFT JOIN $excludeTempTablename temp ON $contact.id = temp.contact_id ")
         ->where('gc.group_id IN (#groups) AND gc.status = "Added"')
         ->merge($criteria)
-        ->groupBy(array("$contact.id", "$entityTable.id"))
-        ->replaceInto($includedTempTablename, array('contact_id', $entityColumn))
+        ->groupBy(["$contact.id", "$entityTable.id"])
+        ->replaceInto($includedTempTablename, ['contact_id', $entityColumn])
         ->param('#groups', $recipientsGroup['Include'])
         ->param('#mailingID', $mailingID)
         ->execute();
@@ -288,7 +293,10 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         ->where('mailing_id IN (#mailings)')
         ->where('temp.contact_id IS NULL')
         ->param('#mailings', $priorMailingIDs['Include'])
-        ->insertIgnoreInto($includedTempTablename, array('contact_id', $entityColumn))
+        ->insertIgnoreInto($includedTempTablename, [
+          'contact_id',
+          $entityColumn,
+        ])
         ->execute();
     }
 
@@ -303,7 +311,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         ->where('gc.group_id IN (#groups)')
         ->where('gcr.status IS NULL OR gcr.status != "Removed"')
         ->merge($criteria)
-        ->replaceInto($includedTempTablename, array('contact_id', $entityColumn))
+        ->replaceInto($includedTempTablename, ['contact_id', $entityColumn])
         ->param('#groups', $includeSmartGroupIDs)
         ->param('#mailingID', $mailingID)
         ->execute();
@@ -311,10 +319,10 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
 
     // Construct the filtered search queries.
     $dao = CRM_Utils_SQL_Select::from('civicrm_mailing_group')
-            ->select('search_id, search_args, entity_id')
-            ->where('search_id IS NOT NULL AND mailing_id = #mailingID')
-            ->param('#mailingID', $mailingID)
-            ->execute();
+      ->select('search_id, search_args, entity_id')
+      ->where('search_id IS NOT NULL AND mailing_id = #mailingID')
+      ->param('#mailingID', $mailingID)
+      ->execute();
     while ($dao->fetch()) {
       $customSQL = CRM_Contact_BAO_SearchCustom::civiMailSQL($dao->search_id,
         $dao->search_args,
@@ -327,18 +335,30 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
     list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause();
 
     // clear all the mailing recipients before populating
-    CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_mailing_recipients WHERE  mailing_id = %1 ", array(1 => array($mailingID, 'Integer')));
-
-    $selectClause = array('#mailingID', 'i.contact_id', "i.$entityColumn");
+    CRM_Core_DAO::executeQuery(" DELETE FROM civicrm_mailing_recipients WHERE  mailing_id = %1 ", [
+      1 => [
+        $mailingID,
+        'Integer',
+      ],
+    ]);
+
+    $selectClause = ['#mailingID', 'i.contact_id', "i.$entityColumn"];
     // CRM-3975
-    $orderBy = array("i.contact_id", "i.$entityColumn");
+    $orderBy = ["i.contact_id", "i.$entityColumn"];
 
-    $query = CRM_Utils_SQL_Select::from('civicrm_contact contact_a')->join('i', " INNER JOIN {$includedTempTablename} i ON contact_a.id = i.contact_id ");
+    $query = CRM_Utils_SQL_Select::from('civicrm_contact contact_a')
+      ->join('i', " INNER JOIN {$includedTempTablename} i ON contact_a.id = i.contact_id ");
     if (!$isSMSmode && $mailingObj->dedupe_email) {
-      $orderBy = array("MIN(i.contact_id)", "MIN(i.$entityColumn)");
-      $query = $query->join('e', " INNER JOIN civicrm_email e ON e.id = i.email_id ")->groupBy("e.email");
+      $orderBy = ["MIN(i.contact_id)", "MIN(i.$entityColumn)"];
+      $query = $query->join('e', " INNER JOIN civicrm_email e ON e.id = i.email_id ")
+        ->groupBy("e.email");
       if (CRM_Utils_SQL::supportsFullGroupBy()) {
-        $selectClause = array('#mailingID', 'ANY_VALUE(i.contact_id) contact_id', "ANY_VALUE(i.$entityColumn) $entityColumn", "e.email");
+        $selectClause = [
+          '#mailingID',
+          'ANY_VALUE(i.contact_id) contact_id',
+          "ANY_VALUE(i.$entityColumn) $entityColumn",
+          "e.email",
+        ];
       }
     }
 
@@ -358,12 +378,12 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
       $sql = $query->toSQL();
       CRM_Utils_SQL_Select::from("( $sql ) AS i ")
         ->select($selectClause)
-        ->insertInto('civicrm_mailing_recipients', array('mailing_id', 'contact_id', $entityColumn))
+        ->insertInto('civicrm_mailing_recipients', ['mailing_id', 'contact_id', $entityColumn])
         ->param('#mailingID', $mailingID)
         ->execute();
     }
     else {
-      $query->insertInto('civicrm_mailing_recipients', array('mailing_id', 'contact_id', $entityColumn))
+      $query->insertInto('civicrm_mailing_recipients', ['mailing_id', 'contact_id', $entityColumn])
         ->param('#mailingID', $mailingID)
         ->execute();
     }
@@ -401,14 +421,14 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         $location_filter = "($email.location_type_id != $location_type_id)";
         // If there is more than one email that doesn't match the location,
         // prefer the one marked is_bulkmail, followed by is_primary.
-        $orderBy = array("$email.is_bulkmail", "$email.is_primary");
+        $orderBy = ["$email.is_bulkmail", "$email.is_primary"];
         break;
 
       case 'location-only':
         $location_filter = "($email.location_type_id = $location_type_id)";
         // If there is more than one email of the desired location, prefer
         // the one marked is_bulkmail, followed by is_primary.
-        $orderBy = array("$email.is_bulkmail", "$email.is_primary");
+        $orderBy = ["$email.is_bulkmail", "$email.is_primary"];
         break;
 
       case 'location-prefer':
@@ -422,17 +442,21 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
         // types are left out, so they will be assigned the value 0. That
         // means, they will all be equally tied for first place, with our
         // location being last.
-        $orderBy = array("FIELD($email.location_type_id, $location_type_id)", "$email.is_bulkmail", "$email.is_primary");
+        $orderBy = [
+          "FIELD($email.location_type_id, $location_type_id)",
+          "$email.is_bulkmail",
+          "$email.is_primary",
+        ];
         break;
 
       case 'automatic':
         // fall through to default
       default:
         $location_filter = "($email.is_bulkmail = 1 OR $email.is_primary = 1)";
-        $orderBy = array("$email.is_bulkmail");
+        $orderBy = ["$email.is_bulkmail"];
     }
 
-    return array($location_filter, $orderBy);
+    return [$location_filter, $orderBy];
   }
 
   /**
@@ -460,7 +484,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
     }
     $mailingGroup->query($query);
 
-    $groupIds = array();
+    $groupIds = [];
     while ($mailingGroup->fetch()) {
       $groupIds[] = $mailingGroup->entity_id;
     }
@@ -477,7 +501,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
    */
   private function getPatterns($onlyHrefs = FALSE) {
 
-    $patterns = array();
+    $patterns = [];
 
     $protos = '(https?|ftp|mailto)';
     $letters = '\w';
@@ -516,19 +540,19 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
     static $_categories = NULL;
     static $_categoryString = NULL;
     if (!$_categories) {
-      $_categories = array(
+      $_categories = [
         'domain' => NULL,
         'action' => NULL,
         'mailing' => NULL,
         'contact' => NULL,
-      );
+      ];
 
       CRM_Utils_Hook::tokens($_categories);
       $_categoryString = implode('|', array_keys($_categories));
     }
 
-    $funcStruct = array('type' => NULL, 'token' => $token);
-    $matches = array();
+    $funcStruct = ['type' => NULL, 'token' => $token];
+    $matches = [];
     if ((preg_match('/^href/i', $token) || preg_match('/^http/i', $token))) {
       // it is a url so we need to check to see if there are any tokens embedded
       // if so then call this function again to get the token dataFunc
@@ -536,7 +560,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
       // will know what how to handle this token.
       if (preg_match_all('/(\{\w+\.\w+\})/', $token, $matches)) {
         $funcStruct['type'] = 'embedded_url';
-        $funcStruct['embed_parts'] = $funcStruct['token'] = array();
+        $funcStruct['embed_parts'] = $funcStruct['token'] = [];
         foreach ($matches[1] as $match) {
           $preg_token = '/' . preg_quote($match, '/') . '/';
           $list = preg_split($preg_token, $token, 2);
@@ -580,20 +604,20 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
       $patterns['subject'] = $patterns['text'] = $this->getPatterns();
       $templates = $this->getTemplates();
 
-      $this->preparedTemplates = array();
+      $this->preparedTemplates = [];
 
-      foreach (array(
+      foreach ([
                  'html',
                  'text',
                  'subject',
-               ) as $key) {
+               ] as $key) {
         if (!isset($templates[$key])) {
           continue;
         }
 
-        $matches = array();
-        $tokens = array();
-        $split_template = array();
+        $matches = [];
+        $tokens = [];
+        $split_template = [];
 
         $email = $templates[$key];
         preg_match_all($patterns[$key], $email, $matches, PREG_PATTERN_ORDER);
@@ -623,9 +647,9 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
   public function getTemplates() {
     if (!$this->templates) {
       $this->getHeaderFooter();
-      $this->templates = array();
+      $this->templates = [];
       if ($this->body_text || !empty($this->header)) {
-        $template = array();
+        $template = [];
         if (!empty($this->header->body_text)) {
           $template[] = $this->header->body_text;
         }
@@ -653,7 +677,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
       // To check for an html part strip tags
       if (trim(strip_tags($this->body_html, '<img>'))) {
 
-        $template = array();
+        $template = [];
         if ($this->header) {
           $template[] = $this->header->body_html;
         }
@@ -675,7 +699,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
       }
 
       if ($this->subject) {
-        $template = array();
+        $template = [];
         $template[] = $this->subject;
         $this->templates['subject'] = implode("\n", $template);
       }
@@ -703,7 +727,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
   public function &getTokens() {
     if (!$this->tokens) {
 
-      $this->tokens = array('html' => array(), 'text' => array(), 'subject' => array());
+      $this->tokens = ['html' => [], 'text' => [], 'subject' => []];
 
       if ($this->body_html) {
         $this->_getTokens('html');
@@ -766,7 +790,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
 
     foreach ($newTokens as $type => $names) {
       if (!isset($this->tokens[$prop][$type])) {
-        $this->tokens[$prop][$type] = array();
+        $this->tokens[$prop][$type] = [];
       }
       foreach ($names as $key => $name) {
         $this->tokens[$prop][$type][] = $name;
@@ -784,14 +808,14 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
    */
   public function getTestRecipients($testParams) {
     if (!empty($testParams['test_group']) && array_key_exists($testParams['test_group'], CRM_Core_PseudoConstant::group())) {
-      $contacts = civicrm_api('contact', 'get', array(
+      $contacts = civicrm_api('contact', 'get', [
           'version' => 3,
           'group' => $testParams['test_group'],
           'return' => 'id',
-          'options' => array(
+          'options' => [
             'limit' => 100000000000,
-          ),
-        )
+          ],
+        ]
       );
 
       foreach (array_keys($contacts['values']) as $groupContact) {
@@ -812,11 +836,11 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 ";
         $dao = CRM_Core_DAO::executeQuery($query);
         if ($dao->fetch()) {
-          $params = array(
+          $params = [
             'job_id' => $testParams['job_id'],
             'email_id' => $dao->email_id,
             'contact_id' => $groupContact,
-          );
+          ];
           CRM_Mailing_Event_BAO_Queue::create($params);
         }
       }
@@ -871,7 +895,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
     $includeMessageId = CRM_Core_BAO_MailSettings::includeMessageId();
-    $fields = array();
+    $fields = [];
     $fields[] = 'Message-ID';
     // CRM-17754 check if Resent-Message-id is set also if not add it in when re-laying reply email
     if ($prefix == 'r') {
@@ -880,12 +904,12 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     foreach ($fields as $field) {
       if ($includeMessageId && (!array_key_exists($field, $headers))) {
         $headers[$field] = '<' . implode($config->verpSeparator,
-            array(
+            [
               $localpart . $prefix,
               $job_id,
               $event_queue_id,
               $hash,
-            )
+            ]
           ) . "@{$emailDomain}>";
       }
     }
@@ -916,7 +940,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 
     // use $bao's instance method to get verp and urls
     list($verp, $urls, $_) = $bao->getVerpAndUrlsAndHeaders($job_id, $event_queue_id, $hash, $email);
-    return array($verp, $urls);
+    return [$verp, $urls];
   }
 
   /**
@@ -947,14 +971,14 @@ ORDER BY   civicrm_email.is_bulkmail DESC
      *  resubscribe:    contact opts back into all target lists for the mailing
      *  optOut:         contact unsubscribes from the domain
      */
-    $verp = array();
-    $verpTokens = array(
+    $verp = [];
+    $verpTokens = [
       'reply' => 'r',
       'bounce' => 'b',
       'unsubscribe' => 'u',
       'resubscribe' => 'e',
       'optOut' => 'o',
-    );
+    ];
 
     $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
@@ -965,12 +989,12 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 
     foreach ($verpTokens as $key => $value) {
       $verp[$key] = implode($config->verpSeparator,
-          array(
+          [
             $localpart . $value,
             $job_id,
             $event_queue_id,
             $hash,
-          )
+          ]
         ) . "@$emailDomain";
     }
 
@@ -983,41 +1007,26 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       $verp['reply'] = "\"{$this->from_name}\" <{$this->from_email}>";
     }
 
-    $urls = array(
-      'forward' => CRM_Utils_System::url('civicrm/mailing/forward',
-        "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}",
-        TRUE, NULL, TRUE, TRUE
-      ),
-      'unsubscribeUrl' => CRM_Utils_System::url('civicrm/mailing/unsubscribe',
-        "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}",
-        TRUE, NULL, TRUE, TRUE
-      ),
-      'resubscribeUrl' => CRM_Utils_System::url('civicrm/mailing/resubscribe',
-        "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}",
-        TRUE, NULL, TRUE, TRUE
-      ),
-      'optOutUrl' => CRM_Utils_System::url('civicrm/mailing/optout',
-        "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}",
-        TRUE, NULL, TRUE, TRUE
-      ),
-      'subscribeUrl' => CRM_Utils_System::url('civicrm/mailing/subscribe',
-        'reset=1',
-        TRUE, NULL, TRUE, TRUE
-      ),
-    );
+    $urls = [
+      'forward' => CRM_Utils_System::url('civicrm/mailing/forward', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", TRUE, NULL, TRUE, TRUE),
+      'unsubscribeUrl' => CRM_Utils_System::url('civicrm/mailing/unsubscribe', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", TRUE, NULL, TRUE, TRUE),
+      'resubscribeUrl' => CRM_Utils_System::url('civicrm/mailing/resubscribe', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", TRUE, NULL, TRUE, TRUE),
+      'optOutUrl' => CRM_Utils_System::url('civicrm/mailing/optout', "reset=1&jid={$job_id}&qid={$event_queue_id}&h={$hash}", TRUE, NULL, TRUE, TRUE),
+      'subscribeUrl' => CRM_Utils_System::url('civicrm/mailing/subscribe', 'reset=1', TRUE, NULL, TRUE, TRUE),
+    ];
 
-    $headers = array(
+    $headers = [
       'Reply-To' => $verp['reply'],
       'Return-Path' => $verp['bounce'],
       'From' => "\"{$this->from_name}\" <{$this->from_email}>",
       'Subject' => $this->subject,
       'List-Unsubscribe' => "<mailto:{$verp['unsubscribe']}>",
-    );
+    ];
     self::addMessageIdHeader($headers, 'm', $job_id, $event_queue_id, $hash);
     if ($isForward) {
       $headers['Subject'] = "[Fwd:{$this->subject}]";
     }
-    return array(&$verp, &$urls, &$headers);
+    return [&$verp, &$urls, &$headers];
   }
 
   /**
@@ -1086,11 +1095,11 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     }
     elseif ($contactId === 0) {
       //anonymous user
-      $contact = array();
+      $contact = [];
       CRM_Utils_Hook::tokenValues($contact, $contactId, $job_id);
     }
     else {
-      $params = array(array('contact_id', '=', $contactId, 0, 0));
+      $params = [['contact_id', '=', $contactId, 0, 0]];
       list($contact) = CRM_Contact_BAO_Query::apiQuery($params);
 
       //CRM-4524
@@ -1098,7 +1107,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 
       if (!$contact || is_a($contact, 'CRM_Core_Error')) {
         CRM_Core_Error::debug_log_message(ts('CiviMail will not send email to a non-existent contact: %1',
-          array(1 => $contactId)
+          [1 => $contactId]
         ));
         // setting this because function is called by reference
         //@todo test not calling function by reference
@@ -1111,11 +1120,11 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     }
 
     $pTemplates = $this->getPreparedTemplates();
-    $pEmails = array();
+    $pEmails = [];
 
     foreach ($pTemplates as $type => $pTemplate) {
       $html = ($type == 'html') ? TRUE : FALSE;
-      $pEmails[$type] = array();
+      $pEmails[$type] = [];
       $pEmail = &$pEmails[$type];
       $template = &$pTemplates[$type]['template'];
       $tokens = &$pTemplates[$type]['tokens'];
@@ -1190,7 +1199,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       // CRM-9833
       // something went wrong, lets log it and return null (by reference)
       CRM_Core_Error::debug_log_message(ts('CiviMail will not send an empty mail body, Skipping: %1',
-        array(1 => $email)
+        [1 => $email]
       ));
       $res = NULL;
       return $res;
@@ -1220,13 +1229,13 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     //cycle through mailParams and set headers array
     foreach ($mailParams as $paramKey => $paramValue) {
       //exclude values not intended for the header
-      if (!in_array($paramKey, array(
+      if (!in_array($paramKey, [
         'text',
         'html',
         'attachments',
         'toName',
         'toEmail',
-      ))
+      ])
       ) {
         $headers[$paramKey] = $paramValue;
       }
@@ -1300,7 +1309,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   public static function tokenReplace(&$mailing) {
     $domain = CRM_Core_BAO_Domain::getDomain();
 
-    foreach (array('text', 'html') as $type) {
+    foreach (['text', 'html'] as $type) {
       $tokens = $mailing->getTokens();
       if (isset($mailing->templates[$type])) {
         $mailing->templates[$type] = CRM_Utils_Token::replaceSubscribeInviteTokens($mailing->templates[$type]);
@@ -1339,7 +1348,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     $useSmarty = defined('CIVICRM_MAIL_SMARTY') && CIVICRM_MAIL_SMARTY ? TRUE : FALSE;
 
     if ($type == 'embedded_url') {
-      $embed_data = array();
+      $embed_data = [];
       foreach ($token as $t) {
         $embed_data[] = $this->getTokenData($t, $html, $contact, $verp, $urls, $event_queue_id);
       }
@@ -1413,7 +1422,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    */
   public function &getGroupNames() {
     if (!isset($this->id)) {
-      return array();
+      return [];
     }
     $mg = new CRM_Mailing_DAO_MailingGroup();
     $mgtable = CRM_Mailing_DAO_MailingGroup::getTableName();
@@ -1426,7 +1435,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
                         AND     $mgtable.group_type = 'Include'
                     ORDER BY    $group.name");
 
-    $groups = array();
+    $groups = [];
     while ($mg->fetch()) {
       $groups[] = $mg->name;
     }
@@ -1445,7 +1454,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    *
    * @return CRM_Mailing_DAO_Mailing
    */
-  public static function add(&$params, $ids = array()) {
+  public static function add(&$params, $ids = []) {
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('mailing_id', $ids));
 
     if (empty($params['id']) && !empty($ids)) {
@@ -1522,7 +1531,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    *   $mailing      The new mailing object
    * @throws \Exception
    */
-  public static function create(&$params, $ids = array()) {
+  public static function create(&$params, $ids = []) {
 
     if (empty($params['id']) && (array_filter($ids) !== [])) {
       $params['id'] = isset($ids['mailing_id']) ? $ids['mailing_id'] : $ids['id'];
@@ -1537,11 +1546,11 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       $domain = civicrm_api(
         'Domain',
         'getsingle',
-        array(
+        [
           'version' => 3,
           'current_domain' => 1,
           'sequential' => 1,
-        )
+        ]
       );
       if (isset($domain['from_email'])) {
         $domain_email = $domain['from_email'];
@@ -1555,7 +1564,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
         $session =& CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
       }
-      $defaults = array(
+      $defaults = [
         // load the default config settings for each
         // eg reply_id, unsubscribe_id need to use
         // correct template IDs here
@@ -1576,7 +1585,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
         'created_date' => date('YmdHis'),
         'scheduled_date' => NULL,
         'approval_date' => NULL,
-      );
+      ];
 
       // Get the default from email address, if not provided.
       if (empty($defaults['from_email'])) {
@@ -1614,9 +1623,13 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 
     /* Create the mailing group record */
     $mg = new CRM_Mailing_DAO_MailingGroup();
-    $groupTypes = array('include' => 'Include', 'exclude' => 'Exclude', 'base' => 'Base');
-    foreach (array('groups', 'mailings') as $entity) {
-      foreach (array('include', 'exclude', 'base') as $type) {
+    $groupTypes = [
+      'include' => 'Include',
+      'exclude' => 'Exclude',
+      'base' => 'Base',
+    ];
+    foreach (['groups', 'mailings'] as $entity) {
+      foreach (['include', 'exclude', 'base'] as $type) {
         if (isset($params[$entity][$type])) {
           self::replaceGroups($mailing->id, $groupTypes[$type], $entity, $params[$entity][$type]);
         }
@@ -1639,7 +1652,8 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 
     // If we're going to autosend, then check validity before saving.
     if (empty($params['is_completed']) && !empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && !empty($params['_evil_bao_validator_'])) {
-      $cb = Civi\Core\Resolver::singleton()->get($params['_evil_bao_validator_']);
+      $cb = Civi\Core\Resolver::singleton()
+        ->get($params['_evil_bao_validator_']);
       $errors = call_user_func($cb, $mailing);
       if (!empty($errors)) {
         $fields = implode(',', array_keys($errors));
@@ -1686,12 +1700,12 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    *   List of error messages.
    */
   public static function checkSendable($mailing) {
-    $errors = array();
-    foreach (array('subject', 'name', 'from_name', 'from_email') as $field) {
+    $errors = [];
+    foreach (['subject', 'name', 'from_name', 'from_email'] as $field) {
       if (empty($mailing->{$field})) {
-        $errors[$field] = ts('Field "%1" is required.', array(
+        $errors[$field] = ts('Field "%1" is required.', [
           1 => $field,
-        ));
+        ]);
       }
     }
     if (empty($mailing->body_html) && empty($mailing->body_text)) {
@@ -1701,7 +1715,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     if (!Civi::settings()->get('disable_mandatory_tokens_check')) {
       $header = $mailing->header_id && $mailing->header_id != 'null' ? CRM_Mailing_BAO_MailingComponent::findById($mailing->header_id) : NULL;
       $footer = $mailing->footer_id && $mailing->footer_id != 'null' ? CRM_Mailing_BAO_MailingComponent::findById($mailing->footer_id) : NULL;
-      foreach (array('body_html', 'body_text') as $field) {
+      foreach (['body_html', 'body_text'] as $field) {
         if (empty($mailing->{$field})) {
           continue;
         }
@@ -1710,7 +1724,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
         if ($err !== TRUE) {
           foreach ($err as $token => $desc) {
             $errors["{$field}:{$token}"] = ts('This message is missing a required token - {%1}: %2',
-              array(1 => $token, 2 => $desc)
+              [1 => $token, 2 => $desc]
             );
           }
         }
@@ -1732,16 +1746,16 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    * @throws CiviCRM_API3_Exception
    */
   public static function replaceGroups($mailingId, $type, $entity, $entityIds) {
-    $values = array();
+    $values = [];
     foreach ($entityIds as $entityId) {
-      $values[] = array('entity_id' => $entityId);
+      $values[] = ['entity_id' => $entityId];
     }
-    civicrm_api3('mailing_group', 'replace', array(
+    civicrm_api3('mailing_group', 'replace', [
       'mailing_id' => $mailingId,
       'group_type' => $type,
       'entity_table' => ($entity == 'groups') ? CRM_Contact_BAO_Group::getTableName() : CRM_Mailing_BAO_Mailing::getTableName(),
       'values' => $values,
-    ));
+    ]);
   }
 
   /**
@@ -1778,7 +1792,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 
     $mailing = new CRM_Mailing_BAO_Mailing();
 
-    $t = array(
+    $t = [
       'mailing' => self::getTableName(),
       'mailing_group' => CRM_Mailing_DAO_MailingGroup::getTableName(),
       'group' => CRM_Contact_BAO_Group::getTableName(),
@@ -1794,9 +1808,9 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       'urlopen' => CRM_Mailing_Event_BAO_TrackableURLOpen::getTableName(),
       'component' => CRM_Mailing_BAO_MailingComponent::getTableName(),
       'spool' => CRM_Mailing_BAO_Spool::getTableName(),
-    );
+    ];
 
-    $report = array();
+    $report = [];
     $additionalWhereClause = " AND ";
     if (!$isSMS) {
       $additionalWhereClause .= " {$t['mailing']}.sms_provider_id IS NULL ";
@@ -1814,7 +1828,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 
     $mailing->fetch();
 
-    $report['mailing'] = array();
+    $report['mailing'] = [];
     foreach (array_keys(self::fields()) as $field) {
       if ($field == 'mailing_modified_date') {
         $field = 'modified_date';
@@ -1836,16 +1850,16 @@ ORDER BY   civicrm_email.is_bulkmail DESC
 
     /* Get the component info */
 
-    $query = array();
+    $query = [];
 
-    $components = array(
+    $components = [
       'header' => ts('Header'),
       'footer' => ts('Footer'),
       'reply' => ts('Reply'),
       'optout' => ts('Opt-Out'),
       'resubscribe' => ts('Resubscribe'),
       'unsubscribe' => ts('Unsubscribe'),
-    );
+    ];
     foreach (array_keys($components) as $type) {
       $query[] = "SELECT          {$t['component']}.name as name,
                                         '$type' as type,
@@ -1859,15 +1873,13 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     $q = '(' . implode(') UNION (', $query) . ')';
     $mailing->query($q);
 
-    $report['component'] = array();
+    $report['component'] = [];
     while ($mailing->fetch()) {
-      $report['component'][] = array(
+      $report['component'][] = [
         'type' => $components[$mailing->type],
         'name' => $mailing->name,
-        'link' => CRM_Utils_System::url('civicrm/mailing/component',
-          "reset=1&action=update&id={$mailing->id}"
-        ),
-      );
+        'link' => CRM_Utils_System::url('civicrm/mailing/component', "reset=1&action=update&id={$mailing->id}"),
+      ];
     }
 
     /* Get the recipient group info */
@@ -1893,9 +1905,9 @@ ORDER BY   civicrm_email.is_bulkmail DESC
             WHERE           {$t['mailing_group']}.mailing_id = $mailing_id
             ");
 
-    $report['group'] = array('include' => array(), 'exclude' => array(), 'base' => array());
+    $report['group'] = ['include' => [], 'exclude' => [], 'base' => []];
     while ($mailing->fetch()) {
-      $row = array();
+      $row = [];
       if (isset($mailing->group_id)) {
         $row['id'] = $mailing->group_id;
         $row['name'] = $mailing->group_title;
@@ -1960,9 +1972,10 @@ ORDER BY   civicrm_email.is_bulkmail DESC
                     AND     {$t['job']}.is_test = 0
             GROUP BY        {$t['job']}.id");
 
-    $report['jobs'] = array();
-    $report['event_totals'] = array();
-    $elements = array(
+    $report['jobs'] = [];
+    $report['event_totals'] = [];
+    $path = 'civicrm/mailing/report/event';
+    $elements = [
       'queue',
       'delivered',
       'url',
@@ -1974,7 +1987,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       'total_opened',
       'bounce',
       'spool',
-    );
+    ];
 
     // initialize various counters
     foreach ($elements as $field) {
@@ -1982,7 +1995,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     }
 
     while ($mailing->fetch()) {
-      $row = array();
+      $row = [];
       foreach ($elements as $field) {
         if (isset($mailing->$field)) {
           $row[$field] = $mailing->$field;
@@ -2026,46 +2039,19 @@ ORDER BY   civicrm_email.is_bulkmail DESC
         $row['clickthrough_rate'] = 0;
       }
 
-      $row['links'] = array(
-        'clicks' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=click&mid=$mailing_id&jid={$mailing->id}"
-        ),
-        'queue' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=queue&mid=$mailing_id&jid={$mailing->id}"
-        ),
-        'delivered' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=delivered&mid=$mailing_id&jid={$mailing->id}"
-        ),
-        'bounce' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=bounce&mid=$mailing_id&jid={$mailing->id}"
-        ),
-        'unsubscribe' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=unsubscribe&mid=$mailing_id&jid={$mailing->id}"
-        ),
-        'forward' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=forward&mid=$mailing_id&jid={$mailing->id}"
-        ),
-        'reply' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=reply&mid=$mailing_id&jid={$mailing->id}"
-        ),
-        'opened' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=opened&mid=$mailing_id&jid={$mailing->id}"
-        ),
-      );
+      $arg = "reset=1&mid=$mailing_id&jid={$mailing->id}";
+      $row['links'] = [
+        'clicks' => CRM_Utils_System::url($path, "$arg&event=click"),
+        'queue' => CRM_Utils_System::url($path, "$arg&event=queue"),
+        'delivered' => CRM_Utils_System::url($path, "$arg&event=delivered"),
+        'bounce' => CRM_Utils_System::url($path, "$arg&event=bounce"),
+        'unsubscribe' => CRM_Utils_System::url($path, "$arg&event=unsubscribe"),
+        'forward' => CRM_Utils_System::url($path, "$arg&event=forward"),
+        'reply' => CRM_Utils_System::url($path, "$arg&event=reply"),
+        'opened' => CRM_Utils_System::url($path, "$arg&event=opened"),
+      ];
 
-      foreach (array(
-                 'scheduled_date',
-                 'start_date',
-                 'end_date',
-               ) as $key) {
+      foreach (['scheduled_date', 'start_date', 'end_date'] as $key) {
         $row[$key] = CRM_Utils_Date::customFormat($row[$key]);
       }
       $report['jobs'][] = $row;
@@ -2118,90 +2104,43 @@ ORDER BY   civicrm_email.is_bulkmail DESC
             GROUP BY    {$t['url']}.id
             ORDER BY    unique_clicks DESC");
 
-    $report['click_through'] = array();
+    $report['click_through'] = [];
 
     while ($mailing->fetch()) {
-      $report['click_through'][] = array(
+      $report['click_through'][] = [
         'url' => $mailing->url,
-        'link' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=click&mid=$mailing_id&uid={$mailing->id}"
-        ),
-        'link_unique' => CRM_Utils_System::url(
-          'civicrm/mailing/report/event',
-          "reset=1&event=click&mid=$mailing_id&uid={$mailing->id}&distinct=1"
-        ),
+        'link' => CRM_Utils_System::url($path, "reset=1&event=click&mid=$mailing_id&uid={$mailing->id}"),
+        'link_unique' => CRM_Utils_System::url($path, "reset=1&event=click&mid=$mailing_id&uid={$mailing->id}&distinct=1"),
         'clicks' => $mailing->clicks,
         'unique' => $mailing->unique_clicks,
         'rate' => CRM_Utils_Array::value('delivered', $report['event_totals']) ? (100.0 * $mailing->unique_clicks) / $report['event_totals']['delivered'] : 0,
         'report' => CRM_Report_Utils_Report::getNextUrl('mailing/clicks', "reset=1&mailing_id_value={$mailing_id}&url_value={$mailing->url}", FALSE, TRUE),
-      );
-    }
-
-    $report['event_totals']['links'] = array(
-      'clicks' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=click&mid=$mailing_id"
-      ),
-      'clicks_unique' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=click&mid=$mailing_id&distinct=1"
-      ),
-      'queue' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=queue&mid=$mailing_id"
-      ),
-      'delivered' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=delivered&mid=$mailing_id"
-      ),
-      'bounce' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=bounce&mid=$mailing_id"
-      ),
-      'unsubscribe' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=unsubscribe&mid=$mailing_id"
-      ),
-      'optout' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=optout&mid=$mailing_id"
-      ),
-      'forward' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=forward&mid=$mailing_id"
-      ),
-      'reply' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=reply&mid=$mailing_id"
-      ),
-      'opened' => CRM_Utils_System::url(
-        'civicrm/mailing/report/event',
-        "reset=1&event=opened&mid=$mailing_id"
-      ),
-    );
-
-    $actionLinks = array(CRM_Core_Action::VIEW => array('name' => ts('Report')));
-    $actionLinks[CRM_Core_Action::ADVANCED] = array(
+      ];
+    }
+
+    $arg = "reset=1&mid=$mailing_id";
+    $report['event_totals']['links'] = [
+      'clicks' => CRM_Utils_System::url($path, "$arg&event=click"),
+      'clicks_unique' => CRM_Utils_System::url($path, "$arg&event=click&distinct=1"),
+      'queue' => CRM_Utils_System::url($path, "$arg&event=queue"),
+      'delivered' => CRM_Utils_System::url($path, "$arg&event=delivered"),
+      'bounce' => CRM_Utils_System::url($path, "$arg&event=bounce"),
+      'unsubscribe' => CRM_Utils_System::url($path, "$arg&event=unsubscribe"),
+      'optout' => CRM_Utils_System::url($path, "$arg&event=optout"),
+      'forward' => CRM_Utils_System::url($path, "$arg&event=forward"),
+      'reply' => CRM_Utils_System::url($path, "$arg&event=reply"),
+      'opened' => CRM_Utils_System::url($path, "$arg&event=opened"),
+    ];
+
+    $actionLinks = [CRM_Core_Action::VIEW => ['name' => ts('Report')]];
+    $actionLinks[CRM_Core_Action::ADVANCED] = [
       'name' => ts('Advanced Search'),
       'url' => 'civicrm/contact/search/advanced',
-    );
+    ];
     $action = array_sum(array_keys($actionLinks));
 
-    $report['event_totals']['actionlinks'] = array();
-    foreach (array(
-               'clicks',
-               'clicks_unique',
-               'queue',
-               'delivered',
-               'bounce',
-               'unsubscribe',
-               'forward',
-               'reply',
-               'opened',
-               'opened_unique',
-               'optout',
-             ) as $key) {
+    $report['event_totals']['actionlinks'] = [];
+    foreach (['clicks', 'clicks_unique', 'queue', 'delivered', 'bounce', 'unsubscribe', 'forward', 'reply', 'opened', 'opened_unique', 'optout'] as $key) {
       $url = 'mailing/detail';
       $reportFilter = "reset=1&mailing_id_value={$mailing_id}";
       $searchFilter = "force=1&mailing_id=%%mid%%";
@@ -2256,7 +2195,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       $report['event_totals']['actionlinks'][$key] = CRM_Core_Action::formLink(
         $actionLinks,
         $action,
-        array('mid' => $mailing_id),
+        ['mid' => $mailing_id],
         ts('more'),
         FALSE,
         'mailing.report.action',
@@ -2348,15 +2287,15 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       return TRUE;
     }
 
-    $mailingIDs = array();
+    $mailingIDs = [];
 
     // get all the groups that this user can access
     // if they dont have universal access
-    $groupNames = civicrm_api3('Group', 'get', array(
+    $groupNames = civicrm_api3('Group', 'get', [
       'check_permissions' => TRUE,
-      'return' => array('title', 'id'),
-      'options' => array('limit' => 0),
-    ));
+      'return' => ['title', 'id'],
+      'options' => ['limit' => 0],
+    ]);
     foreach ($groupNames['values'] as $group) {
       $groups[$group['id']] = $group['title'];
     }
@@ -2374,7 +2313,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
 ";
       $dao = CRM_Core_DAO::executeQuery($query);
 
-      $mailingIDs = array();
+      $mailingIDs = [];
       while ($dao->fetch()) {
         $mailingIDs[] = $dao->id;
       }
@@ -2422,13 +2361,21 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
 
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
-    $select = array(
-      "$mailing.id", "$mailing.name", "$job.status",
-      "$mailing.approval_status_id", "createdContact.sort_name as created_by", "scheduledContact.sort_name as scheduled_by",
-      "$mailing.created_id as created_id", "$mailing.scheduled_id as scheduled_id", "$mailing.is_archived as archived",
-      "$mailing.created_date as created_date", "campaign_id", "$mailing.sms_provider_id as sms_provider_id",
+    $select = [
+      "$mailing.id",
+      "$mailing.name",
+      "$job.status",
+      "$mailing.approval_status_id",
+      "createdContact.sort_name as created_by",
+      "scheduledContact.sort_name as scheduled_by",
+      "$mailing.created_id as created_id",
+      "$mailing.scheduled_id as scheduled_id",
+      "$mailing.is_archived as archived",
+      "$mailing.created_date as created_date",
+      "campaign_id",
+      "$mailing.sms_provider_id as sms_provider_id",
       "$mailing.language",
-    );
+    ];
 
     // we only care about parent jobs, since that holds all the info on
     // the mailing
@@ -2464,14 +2411,14 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
     }
 
     if (!$additionalParams) {
-      $additionalParams = array();
+      $additionalParams = [];
     }
 
     $dao = CRM_Core_DAO::executeQuery($query, $additionalParams);
 
-    $rows = array();
+    $rows = [];
     while ($dao->fetch()) {
-      $rows[] = array(
+      $rows[] = [
         'id' => $dao->id,
         'name' => $dao->name,
         'status' => $dao->status ? $dao->status : 'Not scheduled',
@@ -2490,7 +2437,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
         'campaign' => empty($dao->campaign_id) ? NULL : $allCampaigns[$dao->campaign_id],
         'sms_provider_id' => $dao->sms_provider_id,
         'language' => $dao->language,
-      );
+      ];
     }
     return $rows;
   }
@@ -2562,7 +2509,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
   public function getReturnProperties() {
     $tokens = &$this->getTokens();
 
-    $properties = array();
+    $properties = [];
     if (isset($tokens['html']) &&
       isset($tokens['html']['contact'])
     ) {
@@ -2581,7 +2528,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
       $properties = array_merge($properties, $tokens['subject']['contact']);
     }
 
-    $returnProperties = array();
+    $returnProperties = [];
     $returnProperties['display_name'] = $returnProperties['contact_id'] = $returnProperties['preferred_mail_format'] = $returnProperties['hash'] = 1;
 
     foreach ($properties as $p) {
@@ -2600,7 +2547,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
    */
   public static function commonCompose(&$form) {
     //get the tokens.
-    $tokens = array();
+    $tokens = [];
 
     if (method_exists($form, 'listTokens')) {
       $tokens = array_merge($form->listTokens(), $tokens);
@@ -2609,10 +2556,13 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
     //sorted in ascending order tokens by ignoring word case
     $form->assign('tokens', CRM_Utils_Token::formatTokensForDisplay($tokens));
 
-    $templates = array();
+    $templates = [];
 
-    $textFields = array('text_message' => ts('HTML Format'), 'sms_text_message' => ts('SMS Message'));
-    $modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS');
+    $textFields = [
+      'text_message' => ts('HTML Format'),
+      'sms_text_message' => ts('SMS Message'),
+    ];
+    $modePrefixes = ['Mail' => NULL, 'SMS' => 'SMS'];
 
     $className = CRM_Utils_System::getClassName($form);
 
@@ -2621,11 +2571,11 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
     ) {
       $form->add('wysiwyg', 'html_message',
         strstr($className, 'PDF') ? ts('Document Body') : ts('HTML Format'),
-        array(
+        [
           'cols' => '80',
           'rows' => '8',
           'onkeyup' => "return verify(this)",
-        )
+        ]
       );
 
       if ($className != 'CRM_Admin_Form_ScheduleReminders') {
@@ -2645,11 +2595,11 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
         $form->assign('max_sms_length', CRM_SMS_Provider::MAX_SMS_CHAR);
       }
       $form->add('textarea', $id, $label,
-        array(
+        [
           'cols' => '80',
           'rows' => '8',
           'onkeyup' => "return verify(this, '{$prefix}')",
-        )
+        ]
       );
     }
 
@@ -2664,14 +2614,14 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
         $form->assign('templates', TRUE);
 
         $form->add('select', "{$prefix}template", ts('Use Template'),
-          array('' => ts('- select -')) + $templates[$prefix], FALSE,
-          array('onChange' => "selectValue( this.value, '{$prefix}');")
+          ['' => ts('- select -')] + $templates[$prefix], FALSE,
+          ['onChange' => "selectValue( this.value, '{$prefix}');"]
         );
       }
       $form->add('checkbox', "{$prefix}updateTemplate", ts('Update Template'), NULL);
 
       $form->add('checkbox', "{$prefix}saveTemplate", ts('Save As New Template'), NULL, FALSE,
-        array('onclick' => "showSaveDetails(this, '{$prefix}');")
+        ['onclick' => "showSaveDetails(this, '{$prefix}');"]
       );
       $form->add('text', "{$prefix}saveTemplateName", ts('Template Title'));
     }
@@ -2679,7 +2629,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
     // I'm not sure this is ever called.
     $action = CRM_Utils_Request::retrieve('action', 'String', $form, FALSE);
     if ((CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Task_PDF') &&
-        $action == CRM_Core_Action::VIEW
+      $action == CRM_Core_Action::VIEW
     ) {
       $form->freeze('html_message');
     }
@@ -2702,7 +2652,7 @@ SELECT  $mailing.id as mailing_id
    AND  $group.group_type = 'Base'";
 
     $searchDAO = CRM_Core_DAO::executeQuery($query);
-    $mailingIDs = array();
+    $mailingIDs = [];
     while ($searchDAO->fetch()) {
       $mailingIDs[] = $searchDAO->mailing_id;
     }
@@ -2777,7 +2727,7 @@ SELECT  $mailing.id as mailing_id
    * @return mixed
    */
   public static function overrideVerp($jobID) {
-    static $_cache = array();
+    static $_cache = [];
 
     if (!isset($_cache[$jobID])) {
       $query = "
@@ -2786,7 +2736,7 @@ FROM       civicrm_mailing
 INNER JOIN civicrm_mailing_job ON civicrm_mailing.id = civicrm_mailing_job.mailing_id
 WHERE  civicrm_mailing_job.id = %1
 ";
-      $params = array(1 => array($jobID, 'Integer'));
+      $params = [1 => [$jobID, 'Integer']];
       $_cache[$jobID] = CRM_Core_DAO::singleValueQuery($query, $params);
     }
     return $_cache[$jobID];
@@ -2802,10 +2752,10 @@ WHERE  civicrm_mailing_job.id = %1
     $config = CRM_Core_Config::singleton();
 
     if ($mode == NULL && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
-      throw new CRM_Core_Exception(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the online system administrator guide</a>', array(
-            1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'),
-            2 => "https://docs.civicrm.org/sysadmin/en/latest/setup/civimail/",
-          )));
+      throw new CRM_Core_Exception(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the online system administrator guide</a>', [
+        1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'),
+        2 => "https://docs.civicrm.org/sysadmin/en/latest/setup/civimail/",
+      ]));
     }
 
     // check if we are enforcing number of parallel cron jobs
@@ -2821,7 +2771,8 @@ WHERE  civicrm_mailing_job.id = %1
 
       // Check if we are using global locks
       foreach ($lockArray as $lockID) {
-        $cronLock = Civi::lockManager()->acquire("worker.mailing.send.{$lockID}");
+        $cronLock = Civi::lockManager()
+          ->acquire("worker.mailing.send.{$lockID}");
         if ($cronLock->isAcquired()) {
           $gotCronLock = TRUE;
           break;
@@ -2868,7 +2819,7 @@ AND    e.contact_id IN
     ( SELECT contact_id FROM civicrm_mailing_recipients mr WHERE mailing_id = %1 )
 AND    e.id NOT IN ( SELECT email_id FROM civicrm_mailing_recipients mr WHERE mailing_id = %1 )
 ";
-    $params = array(1 => array($mailingID, 'Integer'));
+    $params = [1 => [$mailingID, 'Integer']];
 
     $dao = CRM_Core_DAO::executeQuery($sql, $params);
   }
@@ -2879,7 +2830,7 @@ AND    e.id NOT IN ( SELECT email_id FROM civicrm_mailing_recipients mr WHERE ma
    * @return mixed
    */
   public static function getMailingsList($isSMS = FALSE) {
-    static $list = array();
+    static $list = [];
     $where = " WHERE ";
     if (!$isSMS) {
       $where .= " civicrm_mailing.sms_provider_id IS NULL ";
@@ -2933,9 +2884,9 @@ ORDER BY civicrm_mailing.name";
     }
 
     // format params and add links
-    $contactMailings = array();
+    $contactMailings = [];
     foreach ($mailings as $mailingId => $values) {
-      $mailing = array();
+      $mailing = [];
       $mailing['subject'] = $values['subject'];
       $mailing['creator_name'] = CRM_Utils_System::href(
         $values['creator_name'],
@@ -2950,21 +2901,21 @@ ORDER BY civicrm_mailing.name";
         "<br />Clicks: " .
         CRM_Utils_Array::value($values['mailing_id'], $clickCounts, 0);
 
-      $actionLinks = array(
-        CRM_Core_Action::VIEW => array(
+      $actionLinks = [
+        CRM_Core_Action::VIEW => [
           'name' => ts('View'),
           'url' => 'civicrm/mailing/view',
           'qs' => "reset=1&id=%%mkey%%",
           'title' => ts('View Mailing'),
           'class' => 'crm-popup',
-        ),
-        CRM_Core_Action::BROWSE => array(
+        ],
+        CRM_Core_Action::BROWSE => [
           'name' => ts('Mailing Report'),
           'url' => 'civicrm/mailing/report',
           'qs' => "mid=%%mid%%&reset=1&cid=%%cid%%&context=mailing",
           'title' => ts('View Mailing Report'),
-        ),
-      );
+        ],
+      ];
 
       $mailingKey = $values['mailing_id'];
       if ($hash = CRM_Mailing_BAO_Mailing::getMailingHash($mailingKey)) {
@@ -2974,11 +2925,11 @@ ORDER BY civicrm_mailing.name";
       $mailing['links'] = CRM_Core_Action::formLink(
         $actionLinks,
         NULL,
-        array(
+        [
           'mid' => $values['mailing_id'],
           'cid' => $params['contact_id'],
           'mkey' => $mailingKey,
-        ),
+        ],
         ts('more'),
         FALSE,
         'mailing.contact.action',
@@ -2989,7 +2940,7 @@ ORDER BY civicrm_mailing.name";
       array_push($contactMailings, $mailing);
     }
 
-    $contactMailingsDT = array();
+    $contactMailingsDT = [];
     $contactMailingsDT['data'] = $contactMailings;
     $contactMailingsDT['recordsTotal'] = $params['total'];
     $contactMailingsDT['recordsFiltered'] = $params['total'];
@@ -3039,27 +2990,37 @@ ORDER BY civicrm_mailing.name";
    */
   public static function getWorkflowFieldPerms() {
     $fieldNames = array_keys(CRM_Mailing_DAO_Mailing::fields());
-    $fieldPerms = array();
+    $fieldPerms = [];
     foreach ($fieldNames as $fieldName) {
       if ($fieldName == 'id') {
-        $fieldPerms[$fieldName] = array(
-          array('access CiviMail', 'schedule mailings', 'approve mailings', 'create mailings'), // OR
-        );
-      }
-      elseif (in_array($fieldName, array('scheduled_date', 'scheduled_id'))) {
-        $fieldPerms[$fieldName] = array(
-          array('access CiviMail', 'schedule mailings'), // OR
-        );
-      }
-      elseif (in_array($fieldName, array('approval_date', 'approver_id', 'approval_status_id', 'approval_note'))) {
-        $fieldPerms[$fieldName] = array(
-          array('access CiviMail', 'approve mailings'), // OR
-        );
+        $fieldPerms[$fieldName] = [
+          [
+            'access CiviMail',
+            'schedule mailings',
+            'approve mailings',
+            'create mailings',
+          ], // OR
+        ];
+      }
+      elseif (in_array($fieldName, ['scheduled_date', 'scheduled_id'])) {
+        $fieldPerms[$fieldName] = [
+          ['access CiviMail', 'schedule mailings'], // OR
+        ];
+      }
+      elseif (in_array($fieldName, [
+        'approval_date',
+        'approver_id',
+        'approval_status_id',
+        'approval_note',
+      ])) {
+        $fieldPerms[$fieldName] = [
+          ['access CiviMail', 'approve mailings'], // OR
+        ];
       }
       else {
-        $fieldPerms[$fieldName] = array(
-          array('access CiviMail', 'create mailings'), // OR
-        );
+        $fieldPerms[$fieldName] = [
+          ['access CiviMail', 'create mailings'], // OR
+        ];
       }
     }
     return $fieldPerms;
@@ -3071,10 +3032,10 @@ ORDER BY civicrm_mailing.name";
    * @return array
    */
   public static function mailingGroupEntityTables() {
-    return array(
+    return [
       CRM_Contact_BAO_Group::getTableName() => 'Group',
       CRM_Mailing_BAO_Mailing::getTableName() => 'Mailing',
-    );
+    ];
   }
 
   /**
@@ -3086,8 +3047,11 @@ ORDER BY civicrm_mailing.name";
    * @return string
    */
   public static function getPublicViewUrl($id, $absolute = TRUE) {
-    if ((civicrm_api3('Mailing', 'getvalue', array('id' => $id, 'return' => 'visibility'))) === 'Public Pages') {
-      return CRM_Utils_System::url('civicrm/mailing/view', array('id' => $id), $absolute, NULL, TRUE, TRUE);
+    if ((civicrm_api3('Mailing', 'getvalue', [
+        'id' => $id,
+        'return' => 'visibility',
+      ])) === 'Public Pages') {
+      return CRM_Utils_System::url('civicrm/mailing/view', ['id' => $id], $absolute, NULL, TRUE, TRUE);
     }
   }
 
@@ -3103,16 +3067,16 @@ ORDER BY civicrm_mailing.name";
    */
   public static function getTemplateTypes() {
     if (!isset(Civi::$statics[__CLASS__]['templateTypes'])) {
-      $types = array();
-      $types[] = array(
+      $types = [];
+      $types[] = [
         'name' => 'traditional',
         'editorUrl' => CRM_Mailing_Info::workflowEnabled() ? '~/crmMailing/EditMailingCtrl/workflow.html' : '~/crmMailing/EditMailingCtrl/2step.html',
         'weight' => 0,
-      );
+      ];
 
       CRM_Utils_Hook::mailingTemplateTypes($types);
 
-      $defaults = array('weight' => 0);
+      $defaults = ['weight' => 0];
       foreach (array_keys($types) as $typeName) {
         $types[$typeName] = array_merge($defaults, $types[$typeName]);
       }
@@ -3136,7 +3100,7 @@ ORDER BY civicrm_mailing.name";
    *   Array(string $name => string $label).
    */
   public static function getTemplateTypeNames() {
-    $r = array();
+    $r = [];
     foreach (self::getTemplateTypes() as $type) {
       $r[$type['name']] = $type['name'];
     }