dev/core#562 Remove more DAO->free() calls
[civicrm-core.git] / CRM / Dedupe / Merger.php
index 228cb643cbc237e4b893ca81f53bacddd4e3ad90..869454b0ca23b997f1fa0d538fbff87713fb74c5 100644 (file)
@@ -51,105 +51,125 @@ class CRM_Dedupe_Merger {
       $config = CRM_Core_Config::singleton();
       if ($config->userSystem->is_drupal) {
         $userRecordUrl = CRM_Utils_System::url('user/%ufid');
-        $title = ts('%1 User: %2; user id: %3', array(1 => $config->userFramework, 2 => '$ufname', 3 => '$ufid'));
+        $title = ts('%1 User: %2; user id: %3', [
+          1 => $config->userFramework,
+          2 => '$ufname',
+          3 => '$ufid',
+        ]);
       }
       elseif ($config->userFramework == 'Joomla') {
         $userRecordUrl = $config->userSystem->getVersion() > 1.5 ? $config->userFrameworkBaseURL . "index.php?option=com_users&view=user&task=user.edit&id=" . '%ufid' : $config->userFrameworkBaseURL . "index2.php?option=com_users&view=user&task=edit&id[]=" . '%ufid';
-        $title = ts('%1 User: %2; user id: %3', array(1 => $config->userFramework, 2 => '$ufname', 3 => '$ufid'));
+        $title = ts('%1 User: %2; user id: %3', [
+          1 => $config->userFramework,
+          2 => '$ufname',
+          3 => '$ufid',
+        ]);
       }
 
-      $relTables = array(
-        'rel_table_contributions' => array(
+      $relTables = [
+        'rel_table_contributions' => [
           'title' => ts('Contributions'),
-          'tables' => array('civicrm_contribution', 'civicrm_contribution_recur', 'civicrm_contribution_soft'),
+          'tables' => [
+            'civicrm_contribution',
+            'civicrm_contribution_recur',
+            'civicrm_contribution_soft',
+          ],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=contribute'),
-        ),
-        'rel_table_contribution_page' => array(
+        ],
+        'rel_table_contribution_page' => [
           'title' => ts('Contribution Pages'),
-          'tables' => array('civicrm_contribution_page'),
+          'tables' => ['civicrm_contribution_page'],
           'url' => CRM_Utils_System::url('civicrm/admin/contribute', 'reset=1&cid=$cid'),
-        ),
-        'rel_table_memberships' => array(
+        ],
+        'rel_table_memberships' => [
           'title' => ts('Memberships'),
-          'tables' => array('civicrm_membership', 'civicrm_membership_log', 'civicrm_membership_type'),
+          'tables' => [
+            'civicrm_membership',
+            'civicrm_membership_log',
+            'civicrm_membership_type',
+          ],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=member'),
-        ),
-        'rel_table_participants' => array(
+        ],
+        'rel_table_participants' => [
           'title' => ts('Participants'),
-          'tables' => array('civicrm_participant'),
+          'tables' => ['civicrm_participant'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=participant'),
-        ),
-        'rel_table_events' => array(
+        ],
+        'rel_table_events' => [
           'title' => ts('Events'),
-          'tables' => array('civicrm_event'),
+          'tables' => ['civicrm_event'],
           'url' => CRM_Utils_System::url('civicrm/event/manage', 'reset=1&cid=$cid'),
-        ),
-        'rel_table_activities' => array(
+        ],
+        'rel_table_activities' => [
           'title' => ts('Activities'),
-          'tables' => array('civicrm_activity', 'civicrm_activity_contact'),
+          'tables' => ['civicrm_activity', 'civicrm_activity_contact'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=activity'),
-        ),
-        'rel_table_relationships' => array(
+        ],
+        'rel_table_relationships' => [
           'title' => ts('Relationships'),
-          'tables' => array('civicrm_relationship'),
+          'tables' => ['civicrm_relationship'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=rel'),
-        ),
-        'rel_table_custom_groups' => array(
+        ],
+        'rel_table_custom_groups' => [
           'title' => ts('Custom Groups'),
-          'tables' => array('civicrm_custom_group'),
+          'tables' => ['civicrm_custom_group'],
           'url' => CRM_Utils_System::url('civicrm/admin/custom/group', 'reset=1'),
-        ),
-        'rel_table_uf_groups' => array(
+        ],
+        'rel_table_uf_groups' => [
           'title' => ts('Profiles'),
-          'tables' => array('civicrm_uf_group'),
+          'tables' => ['civicrm_uf_group'],
           'url' => CRM_Utils_System::url('civicrm/admin/uf/group', 'reset=1'),
-        ),
-        'rel_table_groups' => array(
+        ],
+        'rel_table_groups' => [
           'title' => ts('Groups'),
-          'tables' => array('civicrm_group_contact'),
+          'tables' => ['civicrm_group_contact'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=group'),
-        ),
-        'rel_table_notes' => array(
+        ],
+        'rel_table_notes' => [
           'title' => ts('Notes'),
-          'tables' => array('civicrm_note'),
+          'tables' => ['civicrm_note'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=note'),
-        ),
-        'rel_table_tags' => array(
+        ],
+        'rel_table_tags' => [
           'title' => ts('Tags'),
-          'tables' => array('civicrm_entity_tag'),
+          'tables' => ['civicrm_entity_tag'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=tag'),
-        ),
-        'rel_table_mailings' => array(
+        ],
+        'rel_table_mailings' => [
           'title' => ts('Mailings'),
-          'tables' => array('civicrm_mailing', 'civicrm_mailing_event_queue', 'civicrm_mailing_event_subscribe'),
+          'tables' => [
+            'civicrm_mailing',
+            'civicrm_mailing_event_queue',
+            'civicrm_mailing_event_subscribe',
+          ],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=mailing'),
-        ),
-        'rel_table_cases' => array(
+        ],
+        'rel_table_cases' => [
           'title' => ts('Cases'),
-          'tables' => array('civicrm_case_contact'),
+          'tables' => ['civicrm_case_contact'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=case'),
-        ),
-        'rel_table_grants' => array(
+        ],
+        'rel_table_grants' => [
           'title' => ts('Grants'),
-          'tables' => array('civicrm_grant'),
+          'tables' => ['civicrm_grant'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=grant'),
-        ),
-        'rel_table_pcp' => array(
+        ],
+        'rel_table_pcp' => [
           'title' => ts('PCPs'),
-          'tables' => array('civicrm_pcp'),
+          'tables' => ['civicrm_pcp'],
           'url' => CRM_Utils_System::url('civicrm/contribute/pcp/manage', 'reset=1'),
-        ),
-        'rel_table_pledges' => array(
+        ],
+        'rel_table_pledges' => [
           'title' => ts('Pledges'),
-          'tables' => array('civicrm_pledge', 'civicrm_pledge_payment'),
+          'tables' => ['civicrm_pledge', 'civicrm_pledge_payment'],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid&selectedChild=pledge'),
-        ),
-        'rel_table_users' => array(
+        ],
+        'rel_table_users' => [
           'title' => $title,
-          'tables' => array('civicrm_uf_match'),
+          'tables' => ['civicrm_uf_match'],
           'url' => $userRecordUrl,
-        ),
-      );
+        ],
+      ];
 
       $relTables += self::getMultiValueCustomSets('relTables');
 
@@ -172,13 +192,13 @@ class CRM_Dedupe_Merger {
    */
   public static function getActiveRelTables($cid) {
     $cid = (int) $cid;
-    $groups = array();
+    $groups = [];
 
     $relTables = self::relTables();
     $cidRefs = self::cidRefs();
     $eidRefs = self::eidRefs();
     foreach ($relTables as $group => $params) {
-      $sqls = array();
+      $sqls = [];
       foreach ($params['tables'] as $table) {
         if (isset($cidRefs[$table])) {
           foreach ($cidRefs[$table] as $field) {
@@ -218,7 +238,8 @@ class CRM_Dedupe_Merger {
 
     CRM_Utils_Hook::merge('cidRefs', $contactReferences);
     if ($contactReferences !== $coreReferences) {
-      Civi::log()->warning("Deprecated hook ::merge in context of 'cidRefs. Use entityTypes instead.", array('civi.tag' => 'deprecated'));
+      Civi::log()
+        ->warning("Deprecated hook ::merge in context of 'cidRefs. Use entityTypes instead.", ['civi.tag' => 'deprecated']);
     }
     \Civi::$statics[__CLASS__]['contact_references'] = $contactReferences;
     return \Civi::$statics[__CLASS__]['contact_references'];
@@ -232,14 +253,14 @@ class CRM_Dedupe_Merger {
     if (!$eidRefs) {
       // FIXME: this should be generated dynamically from the schema
       // tables that reference contacts with entity_{id,table}
-      $eidRefs = array(
-        'civicrm_acl' => array('entity_table' => 'entity_id'),
-        'civicrm_acl_entity_role' => array('entity_table' => 'entity_id'),
-        'civicrm_entity_file' => array('entity_table' => 'entity_id'),
-        'civicrm_log' => array('entity_table' => 'entity_id'),
-        'civicrm_mailing_group' => array('entity_table' => 'entity_id'),
-        'civicrm_note' => array('entity_table' => 'entity_id'),
-      );
+      $eidRefs = [
+        'civicrm_acl' => ['entity_table' => 'entity_id'],
+        'civicrm_acl_entity_role' => ['entity_table' => 'entity_id'],
+        'civicrm_entity_file' => ['entity_table' => 'entity_id'],
+        'civicrm_log' => ['entity_table' => 'entity_id'],
+        'civicrm_mailing_group' => ['entity_table' => 'entity_id'],
+        'civicrm_note' => ['entity_table' => 'entity_id'],
+      ];
 
       // Allow hook_civicrm_merge() to adjust $eidRefs
       CRM_Utils_Hook::merge('eidRefs', $eidRefs);
@@ -253,7 +274,7 @@ class CRM_Dedupe_Merger {
   public static function locTables() {
     static $locTables;
     if (!$locTables) {
-      $locTables = array('civicrm_email', 'civicrm_address', 'civicrm_phone');
+      $locTables = ['civicrm_email', 'civicrm_address', 'civicrm_phone'];
 
       // Allow hook_civicrm_merge() to adjust $locTables
       CRM_Utils_Hook::merge('locTables', $locTables);
@@ -271,23 +292,30 @@ class CRM_Dedupe_Merger {
   public static function getMultiValueCustomSets($request) {
 
     if (!isset(Civi::$statics[__CLASS__]['multiValueCustomSets'])) {
-      $data = array(
-        'relTables' => array(),
-        'cidRefs' => array(),
-      );
-      $result = civicrm_api3('custom_group', 'get', array(
+      $data = [
+        'relTables' => [],
+        'cidRefs' => [],
+      ];
+      $result = civicrm_api3('custom_group', 'get', [
         'is_multiple' => 1,
-        'extends' => array('IN' => array('Individual', 'Organization', 'Household', 'Contact')),
-        'return' => array('id', 'title', 'table_name', 'style'),
-      ));
+        'extends' => [
+          'IN' => [
+            'Individual',
+            'Organization',
+            'Household',
+            'Contact',
+          ],
+        ],
+        'return' => ['id', 'title', 'table_name', 'style'],
+      ]);
       foreach ($result['values'] as $custom) {
-        $data['cidRefs'][$custom['table_name']] = array('entity_id');
+        $data['cidRefs'][$custom['table_name']] = ['entity_id'];
         $urlSuffix = $custom['style'] == 'Tab' ? '&selectedChild=custom_' . $custom['id'] : '';
-        $data['relTables']['rel_table_custom_' . $custom['id']] = array(
+        $data['relTables']['rel_table_custom_' . $custom['id']] = [
           'title' => $custom['title'],
-          'tables' => array($custom['table_name']),
+          'tables' => [$custom['table_name']],
           'url' => CRM_Utils_System::url('civicrm/contact/view', 'reset=1&force=1&cid=$cid' . $urlSuffix),
-        );
+        ];
       }
 
       // Store the result in a static variable cache
@@ -304,14 +332,14 @@ class CRM_Dedupe_Merger {
   public static function cpTables() {
     static $tables;
     if (!$tables) {
-      $tables = array(
-        'civicrm_case_contact' => array('CRM_Case_BAO_Case' => 'mergeContacts'),
-        'civicrm_group_contact' => array('CRM_Contact_BAO_GroupContact' => 'mergeGroupContact'),
+      $tables = [
+        'civicrm_case_contact' => ['CRM_Case_BAO_Case' => 'mergeContacts'],
+        'civicrm_group_contact' => ['CRM_Contact_BAO_GroupContact' => 'mergeGroupContact'],
         // Empty array == do nothing - this table is handled by mergeGroupContact
-        'civicrm_subscription_history' => array(),
-        'civicrm_relationship' => array('CRM_Contact_BAO_Relationship' => 'mergeRelationships'),
-        'civicrm_membership' => array('CRM_Member_BAO_Membership' => 'mergeMemberships'),
-      );
+        'civicrm_subscription_history' => [],
+        'civicrm_relationship' => ['CRM_Contact_BAO_Relationship' => 'mergeRelationships'],
+        'civicrm_membership' => ['CRM_Member_BAO_Membership' => 'mergeMemberships'],
+      ];
     }
     return $tables;
   }
@@ -322,7 +350,7 @@ class CRM_Dedupe_Merger {
   public static function paymentTables() {
     static $tables;
     if (!$tables) {
-      $tables = array('civicrm_pledge', 'civicrm_membership', 'civicrm_participant');
+      $tables = ['civicrm_pledge', 'civicrm_membership', 'civicrm_participant'];
     }
     return $tables;
   }
@@ -337,7 +365,7 @@ class CRM_Dedupe_Merger {
    * @return array
    */
   public static function paymentSql($tableName, $mainContactId, $otherContactId) {
-    $sqls = array();
+    $sqls = [];
     if (!$tableName || !$mainContactId || !$otherContactId) {
       return $sqls;
     }
@@ -388,8 +416,8 @@ INNER JOIN  civicrm_participant participant ON ( participant.id = payment.partic
    *
    * @return array
    */
-  public static function operationSql($mainId, $otherId, $tableName, $tableOperations = array(), $mode = 'add') {
-    $sqls = array();
+  public static function operationSql($mainId, $otherId, $tableName, $tableOperations = [], $mode = 'add') {
+    $sqls = [];
     if (!$tableName || !$mainId || !$otherId) {
       return $sqls;
     }
@@ -439,18 +467,18 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     if (in_array("civicrm_membership", $tables)) {
       $membershipIDs = CRM_Utils_Array::collect('id',
         CRM_Utils_Array::value('values',
-          civicrm_api3("Membership", "get", array(
+          civicrm_api3("Membership", "get", [
             "contact_id" => $otherID,
-            "return"     => "id",
-          )
-          )
-        ));
+            "return" => "id",
+          ])
+        )
+      );
 
       if (!empty($membershipIDs)) {
-        civicrm_api3("Membership", "get", array(
-          'owner_membership_id' => array('IN' => $membershipIDs),
-          'api.Membership.delete' => array('id' => '$value.id'),
-        ));
+        civicrm_api3("Membership", "get", [
+          'owner_membership_id' => ['IN' => $membershipIDs],
+          'api.Membership.delete' => ['id' => '$value.id'],
+        ]);
       }
     }
   }
@@ -465,14 +493,14 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @param array $tableOperations
    * @param array $customTableToCopyFrom
    */
-  public static function moveContactBelongings($mainId, $otherId, $tables = FALSE, $tableOperations = array(), $customTableToCopyFrom = NULL) {
+  public static function moveContactBelongings($mainId, $otherId, $tables = FALSE, $tableOperations = [], $customTableToCopyFrom = NULL) {
     $cidRefs = self::cidRefs();
     $eidRefs = self::eidRefs();
     $cpTables = self::cpTables();
     $paymentTables = self::paymentTables();
 
     // getting all custom tables
-    $customTables = array();
+    $customTables = [];
     if ($customTableToCopyFrom !== NULL) {
       // @todo this duplicates cidRefs?
       CRM_Core_DAO::appendCustomTablesExtendingContacts($customTables);
@@ -496,7 +524,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     $otherId = (int) $otherId;
     $multi_value_tables = array_keys(CRM_Dedupe_Merger::getMultiValueCustomSets('cidRefs'));
 
-    $sqls = array();
+    $sqls = [];
     foreach ($affected as $table) {
       // skipping non selected single-value custom table's value migration
       if (!in_array($table, $multi_value_tables)) {
@@ -554,7 +582,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     // call the SQL queries in one transaction
     $transaction = new CRM_Core_Transaction();
     foreach ($sqls as $sql) {
-      CRM_Core_DAO::executeQuery($sql, array(), TRUE, NULL, TRUE);
+      CRM_Core_DAO::executeQuery($sql, [], TRUE, NULL, TRUE);
     }
     CRM_Dedupe_Merger::addMembershipToRealtedContacts($mainId);
     $transaction->commit();
@@ -598,10 +626,10 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @return array
    */
   public static function retrieveFields($main, $other) {
-    $result = array(
-      'contact' => array(),
-      'custom' => array(),
-    );
+    $result = [
+      'contact' => [],
+      'custom' => [],
+    ];
     foreach (self::getContactFields() as $validField) {
       // CRM-17556 Get all non-empty fields, to make comparison easier
       if (!empty($main[$validField]) || !empty($other[$validField])) {
@@ -658,7 +686,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    *
    * @return array|bool
    */
-  public static function batchMerge($rgid, $gid = NULL, $mode = 'safe', $batchLimit = 1, $isSelected = 2, $criteria = array(), $checkPermissions = TRUE, $reloadCacheIfEmpty = NULL) {
+  public static function batchMerge($rgid, $gid = NULL, $mode = 'safe', $batchLimit = 1, $isSelected = 2, $criteria = [], $checkPermissions = TRUE, $reloadCacheIfEmpty = NULL) {
     $redirectForPerformance = ($batchLimit > 1) ? TRUE : FALSE;
 
     if (!isset($reloadCacheIfEmpty)) {
@@ -670,14 +698,14 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     }
     $dupePairs = self::getDuplicatePairs($rgid, $gid, $reloadCacheIfEmpty, $batchLimit, $isSelected, '', ($mode == 'aggressive'), $criteria, $checkPermissions);
 
-    $cacheParams = array(
+    $cacheParams = [
       'cache_key_string' => self::getMergeCacheKeyString($rgid, $gid, $criteria, $checkPermissions),
       // @todo stop passing these parameters in & instead calculate them in the merge function based
       // on the 'real' params like $isRespectExclusions $batchLimit and $isSelected.
       'join' => self::getJoinOnDedupeTable(),
       'where' => self::getWhereString($isSelected),
       'limit' => (int) $batchLimit,
-    );
+    ];
     return CRM_Dedupe_Merger::merge($dupePairs, $cacheParams, $mode, $redirectForPerformance, $checkPermissions);
   }
 
@@ -717,9 +745,9 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @param string $cacheKeyString
    * @param array $result
    */
-  public static function updateMergeStats($cacheKeyString, $result = array()) {
+  public static function updateMergeStats($cacheKeyString, $result = []) {
     // gather latest stats
-    $merged  = count($result['merged']);
+    $merged = count($result['merged']);
     $skipped = count($result['skipped']);
 
     if ($merged <= 0 && $skipped <= 0) {
@@ -741,13 +769,13 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
 
     // store the updated stats
-    $data = array(
-      'merged'  => $merged,
+    $data = [
+      'merged' => $merged,
       'skipped' => $skipped,
-    );
+    ];
     $data = CRM_Core_DAO::escapeString(serialize($data));
 
-    $values   = array();
+    $values = [];
     $values[] = " ( 'civicrm_contact', 0, 0, '{$cacheKeyString}_stats', '$data' ) ";
     CRM_Core_BAO_PrevNextCache::setItem($values);
   }
@@ -787,10 +815,16 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
   public static function getMergeStatsMsg($stats) {
     $msg = '';
     if (!empty($stats['merged'])) {
-      $msg = '<p>' . ts('One contact merged.', array('count' => $stats['merged'], 'plural' => '%count contacts merged.')) . '</p>';
+      $msg = '<p>' . ts('One contact merged.', [
+        'count' => $stats['merged'],
+        'plural' => '%count contacts merged.',
+      ]) . '</p>';
     }
     if (!empty($stats['skipped'])) {
-      $msg .= '<p>' . ts('One contact was skipped.', array('count' => $stats['skipped'], 'plural' => '%count contacts were skipped.')) . '</p>';
+      $msg .= '<p>' . ts('One contact was skipped.', [
+        'count' => $stats['skipped'],
+        'plural' => '%count contacts were skipped.',
+      ]) . '</p>';
     }
     return $msg;
   }
@@ -816,15 +850,15 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    *
    * @return array|bool
    */
-  public static function merge($dupePairs = array(), $cacheParams = array(), $mode = 'safe',
-     $redirectForPerformance = FALSE, $checkPermissions = TRUE
+  public static function merge($dupePairs = [], $cacheParams = [], $mode = 'safe',
+                               $redirectForPerformance = FALSE, $checkPermissions = TRUE
   ) {
     $cacheKeyString = CRM_Utils_Array::value('cache_key_string', $cacheParams);
-    $resultStats = array('merged' => array(), 'skipped' => array());
+    $resultStats = ['merged' => [], 'skipped' => []];
 
     // we don't want dupe caching to get reset after every-merge, and therefore set the
     CRM_Core_Config::setPermitCacheFlushMode(FALSE);
-    $deletedContacts = array();
+    $deletedContacts = [];
 
     while (!empty($dupePairs)) {
       foreach ($dupePairs as $index => $dupes) {
@@ -859,7 +893,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           $cacheParams['where'],
           0,
           $cacheParams['limit'],
-          array(),
+          [],
           '',
           FALSE
         );
@@ -893,7 +927,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    *
    * @return bool
    */
-  public static function skipMerge($mainId, $otherId, &$migrationInfo, $mode = 'safe', &$conflicts = array()) {
+  public static function skipMerge($mainId, $otherId, &$migrationInfo, $mode = 'safe', &$conflicts = []) {
 
     $originalMigrationInfo = $migrationInfo;
     foreach ($migrationInfo as $key => $val) {
@@ -965,13 +999,13 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     // there's a conflict (to handle "gotchas"). fields_in_conflict could be modified here
     // merge happens with new values filled in here. For a particular field / row not to be merged
     // field should be unset from fields_in_conflict.
-    $migrationData = array(
+    $migrationData = [
       'old_migration_info' => $originalMigrationInfo,
       'mode' => $mode,
       'fields_in_conflict' => $conflicts,
       'merge_mode' => $mode,
       'migration_info' => $migrationInfo,
-    );
+    ];
     CRM_Utils_Hook::merge('batch', $migrationData, $mainId, $otherId);
     $conflicts = $migrationData['fields_in_conflict'];
     // allow hook to override / manipulate migrationInfo as well
@@ -1004,8 +1038,16 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    *
    * @return bool
    */
-  static public function locationIsSame($mainAddress, $comparisonAddress) {
-    $keysToIgnore = array('id', 'is_primary', 'is_billing', 'manual_geo_code', 'contact_id', 'reset_date', 'hold_date');
+  public static function locationIsSame($mainAddress, $comparisonAddress) {
+    $keysToIgnore = [
+      'id',
+      'is_primary',
+      'is_billing',
+      'manual_geo_code',
+      'contact_id',
+      'reset_date',
+      'hold_date',
+    ];
     foreach ($comparisonAddress as $field => $value) {
       if (in_array($field, $keysToIgnore)) {
         continue;
@@ -1024,43 +1066,43 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @return array
    */
   public static function getLocationBlockInfo() {
-    $locationBlocks = array(
-      'address' => array(
+    $locationBlocks = [
+      'address' => [
         'label' => 'Address',
         'displayField' => 'display',
         'sortString' => 'location_type_id',
         'hasLocation' => TRUE,
         'hasType' => FALSE,
-      ),
-      'email' => array(
+      ],
+      'email' => [
         'label' => 'Email',
         'displayField' => 'display',
         'sortString' => 'location_type_id',
         'hasLocation' => TRUE,
         'hasType' => FALSE,
-      ),
-      'im' => array(
+      ],
+      'im' => [
         'label' => 'IM',
         'displayField' => 'name',
         'sortString' => 'location_type_id,provider_id',
         'hasLocation' => TRUE,
         'hasType' => 'provider_id',
-      ),
-      'phone' => array(
+      ],
+      'phone' => [
         'label' => 'Phone',
         'displayField' => 'phone',
         'sortString' => 'location_type_id,phone_type_id',
         'hasLocation' => TRUE,
         'hasType' => 'phone_type_id',
-      ),
-      'website' => array(
+      ],
+      'website' => [
         'label' => 'Website',
         'displayField' => 'url',
         'sortString' => 'website_type_id',
         'hasLocation' => FALSE,
         'hasType' => 'website_type_id',
-      ),
-    );
+      ],
+    ];
     return $locationBlocks;
   }
 
@@ -1124,14 +1166,14 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
 
     $compareFields = self::retrieveFields($main, $other);
 
-    $rows = $elements = $relTableElements = $migrationInfo = array();
+    $rows = $elements = $relTableElements = $migrationInfo = [];
 
     foreach ($compareFields['contact'] as $field) {
       if ($field == 'contact_sub_type') {
         // CRM-15681 don't display sub-types in UI
         continue;
       }
-      foreach (array('main', 'other') as $moniker) {
+      foreach (['main', 'other'] as $moniker) {
         $contact = &$$moniker;
         $value = CRM_Utils_Array::value($field, $contact);
         if (isset($specialValues[$moniker][$field]) && is_string($specialValues[$moniker][$field])) {
@@ -1162,7 +1204,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           $label = CRM_Utils_Array::value('individual_suffix', $contact);
         }
         elseif ($field == 'gender_id' && !empty($value)) {
-          $genderOptions = civicrm_api3('contact', 'getoptions', array('field' => 'gender_id'));
+          $genderOptions = civicrm_api3('contact', 'getoptions', ['field' => 'gender_id']);
           $label = $genderOptions['values'][$value];
         }
         elseif ($field == 'current_employer_id' && !empty($value)) {
@@ -1183,7 +1225,14 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
 
           // Display a checkbox to migrate, only if the values are different
           if ($value != $main[$field]) {
-            $elements[] = array('advcheckbox', "move_$field", NULL, NULL, NULL, $value);
+            $elements[] = [
+              'advcheckbox',
+              "move_$field",
+              NULL,
+              NULL,
+              NULL,
+              $value,
+            ];
           }
 
           $migrationInfo["move_$field"] = $value;
@@ -1198,29 +1247,29 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     // Set up useful information about the location blocks
     $locationBlocks = self::getLocationBlockInfo();
 
-    $locations = array(
-      'main' => array(),
-      'other' => array(),
-    );
+    $locations = [
+      'main' => [],
+      'other' => [],
+    ];
 
     // @todo This could probably be defined and used earlier
-    $mergeTargets = array(
+    $mergeTargets = [
       'main' => $mainId,
       'other' => $otherId,
-    );
+    ];
 
     foreach ($locationBlocks as $blockName => $blockInfo) {
 
       // Collect existing fields from both 'main' and 'other' contacts first
       // This allows us to match up location/types when building the table rows
       foreach ($mergeTargets as $moniker => $cid) {
-        $searchParams = array(
+        $searchParams = [
           'contact_id' => $cid,
           // CRM-17556 Order by field-specific criteria
-          'options' => array(
+          'options' => [
             'sort' => $blockInfo['sortString'],
-          ),
-        );
+          ],
+        ];
         $values = civicrm_api3($blockName, 'get', $searchParams);
         if ($values['count']) {
           $cnt = 0;
@@ -1285,16 +1334,25 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           }
 
           // Add checkbox to migrate data from 'other' to 'main'
-          $elements[] = array('advcheckbox', "move_location_{$blockName}_{$count}");
+          $elements[] = ['advcheckbox', "move_location_{$blockName}_{$count}"];
 
           // Add checkbox to set the 'other' location as primary
-          $elements[] = array('advcheckbox', "location_blocks[$blockName][$count][set_other_primary]", NULL, ts('Set as primary'));
+          $elements[] = [
+            'advcheckbox',
+            "location_blocks[$blockName][$count][set_other_primary]",
+            NULL,
+            ts('Set as primary'),
+          ];
 
           // Flag up this field to skipMerge function (@todo: do we need to?)
           $migrationInfo["move_location_{$blockName}_{$count}"] = 1;
 
           // Add a hidden field to store the ID of the target main contact block
-          $elements[] = array('hidden', "location_blocks[$blockName][$count][mainContactBlockId]", $mainContactBlockId);
+          $elements[] = [
+            'hidden',
+            "location_blocks[$blockName][$count][mainContactBlockId]",
+            $mainContactBlockId,
+          ];
 
           // Setup variables
           $thisTypeId = FALSE;
@@ -1306,29 +1364,34 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           if ($blockInfo['hasLocation']) {
 
             // Load the location options for this entity
-            $locationOptions = civicrm_api3($blockName, 'getoptions', array('field' => 'location_type_id'));
+            $locationOptions = civicrm_api3($blockName, 'getoptions', ['field' => 'location_type_id']);
 
             $thisLocId = $value['location_type_id'];
 
             // Put this field's location type at the top of the list
             $tmpIdList = $locationOptions['values'];
-            $defaultLocId = array($thisLocId => $tmpIdList[$thisLocId]);
+            $defaultLocId = [$thisLocId => $tmpIdList[$thisLocId]];
             unset($tmpIdList[$thisLocId]);
 
             // Add the element
-            $elements[] = array(
+            $elements[] = [
               'select',
               "location_blocks[$blockName][$count][locTypeId]",
               NULL,
               $defaultLocId + $tmpIdList,
-            );
+            ];
 
             // Add the relevant information to the $migrationInfo
             // Keep location-type-id same as that of other-contact
             // @todo Check this logic out
             $migrationInfo['location_blocks'][$blockName][$count]['locTypeId'] = $thisLocId;
             if ($blockName != 'address') {
-              $elements[] = array('advcheckbox', "location_blocks[{$blockName}][$count][operation]", NULL, ts('Add new'));
+              $elements[] = [
+                'advcheckbox',
+                "location_blocks[{$blockName}][$count][operation]",
+                NULL,
+                ts('Add new'),
+              ];
               // always use add operation
               $migrationInfo['location_blocks'][$blockName][$count]['operation'] = 1;
             }
@@ -1341,22 +1404,22 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           if ($blockInfo['hasType']) {
 
             // Load the type options for this entity
-            $typeOptions = civicrm_api3($blockName, 'getoptions', array('field' => $blockInfo['hasType']));
+            $typeOptions = civicrm_api3($blockName, 'getoptions', ['field' => $blockInfo['hasType']]);
 
             $thisTypeId = CRM_Utils_Array::value($blockInfo['hasType'], $value);
 
             // Put this field's location type at the top of the list
             $tmpIdList = $typeOptions['values'];
-            $defaultTypeId = array($thisTypeId => CRM_Utils_Array::value($thisTypeId, $tmpIdList));
+            $defaultTypeId = [$thisTypeId => CRM_Utils_Array::value($thisTypeId, $tmpIdList)];
             unset($tmpIdList[$thisTypeId]);
 
             // Add the element
-            $elements[] = array(
+            $elements[] = [
               'select',
               "location_blocks[$blockName][$count][typeTypeId]",
               NULL,
               $defaultTypeId + $tmpIdList,
-            );
+            ];
 
             // Add the information to the migrationInfo
             $migrationInfo['location_blocks'][$blockName][$count]['typeTypeId'] = $thisTypeId;
@@ -1415,7 +1478,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
         continue;
       }
 
-      $relTableElements[] = array('checkbox', "move_$name");
+      $relTableElements[] = ['checkbox', "move_$name"];
       $migrationInfo["move_$name"] = 1;
 
       $relTables[$name]['main_url'] = str_replace('$cid', $mainId, $relTables[$name]['url']);
@@ -1423,13 +1486,13 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       if ($name == 'rel_table_users') {
         $relTables[$name]['main_url'] = str_replace('%ufid', $mainUfId, $relTables[$name]['url']);
         $relTables[$name]['other_url'] = str_replace('%ufid', $otherUfId, $relTables[$name]['url']);
-        $find = array('$ufid', '$ufname');
+        $find = ['$ufid', '$ufname'];
         if ($mainUser) {
-          $replace = array($mainUfId, $mainUser->name);
+          $replace = [$mainUfId, $mainUser->name];
           $relTables[$name]['main_title'] = str_replace($find, $replace, $relTables[$name]['title']);
         }
         if ($otherUser) {
-          $replace = array($otherUfId, $otherUser->name);
+          $replace = [$otherUfId, $otherUser->name];
           $relTables[$name]['other_title'] = str_replace($find, $replace, $relTables[$name]['title']);
         }
       }
@@ -1443,7 +1506,13 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
             $attributes = [];
           }
         }
-        $elements[] = array('checkbox', "operation[move_{$name}][add]", NULL, ts('add new'), $attributes);
+        $elements[] = [
+          'checkbox',
+          "operation[move_{$name}][add]",
+          NULL,
+          ts('add new'),
+          $attributes,
+        ];
         $migrationInfo["operation"]["move_{$name}"]['add'] = 1;
       }
     }
@@ -1489,13 +1558,20 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           }
           $rows["move_custom_$fid"]['title'] = $field['label'];
 
-          $elements[] = array('advcheckbox', "move_custom_$fid", NULL, NULL, NULL, $value);
+          $elements[] = [
+            'advcheckbox',
+            "move_custom_$fid",
+            NULL,
+            NULL,
+            NULL,
+            $value,
+          ];
           $migrationInfo["move_custom_$fid"] = $value;
         }
       }
     }
 
-    $result = array(
+    $result = [
       'rows' => $rows,
       'elements' => $elements,
       'rel_table_elements' => $relTableElements,
@@ -1503,7 +1579,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       'main_details' => $main,
       'other_details' => $other,
       'migration_info' => $migrationInfo,
-    );
+    ];
 
     $result['main_details']['location_blocks'] = $locations['main'];
     $result['other_details']['location_blocks'] = $locations['other'];
@@ -1535,7 +1611,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
 
     $qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
     $relTables = CRM_Dedupe_Merger::relTables();
-    $submittedCustomFields = $moveTables = $locationMigrationInfo = $tableOperations = $removeTables = array();
+    $submittedCustomFields = $moveTables = $locationMigrationInfo = $tableOperations = $removeTables = [];
 
     foreach ($migrationInfo as $key => $value) {
       if ($value == $qfZeroBug) {
@@ -1578,28 +1654,46 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     if (!empty($removeTables)) {
       // **** CRM-20421
       CRM_Dedupe_Merger::removeContactBelongings($otherId, $removeTables);
-      $removeTables = array();
+      $removeTables = [];
     }
 
     // FIXME: fix gender, prefix and postfix, so they're edible by createProfileContact()
-    $names['gender'] = array('newName' => 'gender_id', 'groupName' => 'gender');
-    $names['individual_prefix'] = array('newName' => 'prefix_id', 'groupName' => 'individual_prefix');
-    $names['individual_suffix'] = array('newName' => 'suffix_id', 'groupName' => 'individual_suffix');
-    $names['communication_style'] = array('newName' => 'communication_style_id', 'groupName' => 'communication_style');
-    $names['addressee'] = array('newName' => 'addressee_id', 'groupName' => 'addressee');
-    $names['email_greeting'] = array('newName' => 'email_greeting_id', 'groupName' => 'email_greeting');
-    $names['postal_greeting'] = array('newName' => 'postal_greeting_id', 'groupName' => 'postal_greeting');
+    $names['gender'] = ['newName' => 'gender_id', 'groupName' => 'gender'];
+    $names['individual_prefix'] = [
+      'newName' => 'prefix_id',
+      'groupName' => 'individual_prefix',
+    ];
+    $names['individual_suffix'] = [
+      'newName' => 'suffix_id',
+      'groupName' => 'individual_suffix',
+    ];
+    $names['communication_style'] = [
+      'newName' => 'communication_style_id',
+      'groupName' => 'communication_style',
+    ];
+    $names['addressee'] = [
+      'newName' => 'addressee_id',
+      'groupName' => 'addressee',
+    ];
+    $names['email_greeting'] = [
+      'newName' => 'email_greeting_id',
+      'groupName' => 'email_greeting',
+    ];
+    $names['postal_greeting'] = [
+      'newName' => 'postal_greeting_id',
+      'groupName' => 'postal_greeting',
+    ];
     CRM_Core_OptionGroup::lookupValues($submitted, $names, TRUE);
 
     // fix custom fields so they're edible by createProfileContact()
-    $treeCache = array();
+    $treeCache = [];
     if (!array_key_exists($migrationInfo['main_details']['contact_type'], $treeCache)) {
       $treeCache[$migrationInfo['main_details']['contact_type']] = CRM_Core_BAO_CustomGroup::getTree(
         $migrationInfo['main_details']['contact_type'],
         NULL,
         NULL,
         -1,
-        array(),
+        [],
         NULL,
         TRUE,
         NULL,
@@ -1608,7 +1702,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       );
     }
 
-    $cFields = array();
+    $cFields = [];
     foreach ($treeCache[$migrationInfo['main_details']['contact_type']] as $key => $group) {
       if (!isset($group['fields'])) {
         continue;
@@ -1619,7 +1713,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     }
 
     if (!isset($submitted)) {
-      $submitted = array();
+      $submitted = [];
     }
     foreach ($submitted as $key => $value) {
       if (substr($key, 0, 7) == 'custom_') {
@@ -1651,12 +1745,12 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           case 'Multi-Select State/Province':
             // Merge values from both contacts for multivalue fields, CRM-4385
             // get the existing custom values from db.
-            $customParams = array('entityID' => $mainId, $key => TRUE);
+            $customParams = ['entityID' => $mainId, $key => TRUE];
             $customfieldValues = CRM_Core_BAO_CustomValueTable::getValues($customParams);
             if (!empty($customfieldValues[$key])) {
               $existingValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $customfieldValues[$key]);
               if (is_array($existingValue) && !empty($existingValue)) {
-                $mergeValue = $submittedCustomFields = array();
+                $mergeValue = $submittedCustomFields = [];
                 if ($value == 'null') {
                   // CRM-19074 if someone has deliberately chosen to overwrite with 'null', respect it.
                   $submitted[$key] = $value;
@@ -1676,10 +1770,10 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
 
                   //keep state and country as array format.
                   //for checkbox and m-select format w/ VALUE_SEPARATOR
-                  if (in_array($htmlType, array(
+                  if (in_array($htmlType, [
                     'CheckBox',
                     'Multi-Select',
-                  ))) {
+                  ])) {
                     $submitted[$key] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
                         $mergeValue
                       ) . CRM_Core_DAO::VALUE_SEPARATOR;
@@ -1690,15 +1784,15 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
                 }
               }
             }
-            elseif (in_array($htmlType, array(
+            elseif (in_array($htmlType, [
               'Multi-Select Country',
               'Multi-Select State/Province',
-            ))) {
+            ])) {
               //we require submitted values should be in array format
               if ($value) {
                 $mergeValueArray = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value);
                 //hack to remove null values from array.
-                $mergeValue = array();
+                $mergeValue = [];
                 foreach ($mergeValueArray as $k => $v) {
                   if ($v != '') {
                     $mergeValue[] = $v;
@@ -1721,13 +1815,13 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     // like, delete a file...
 
     if (!isset($customFiles)) {
-      $customFiles = array();
+      $customFiles = [];
     }
     foreach ($customFiles as $customId) {
       list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($customId);
 
       // get the contact_id -> file_id mapping
-      $fileIds = array();
+      $fileIds = [];
       $sql = "SELECT entity_id, {$columnName} AS file_id FROM {$tableName} WHERE entity_id IN ({$mainId}, {$otherId})";
       $dao = CRM_Core_DAO::executeQuery($sql);
       while ($dao->fetch()) {
@@ -1736,7 +1830,6 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           CRM_Core_BAO_File::deleteFileReferences($fileIds[$mainId], $mainId, $customId);
         }
       }
-      $dao->free();
 
       // move the other contact's file to main contact
       //NYSS need to INSERT or UPDATE depending on whether main contact has an existing record
@@ -1767,7 +1860,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     }
 
     // move view only custom fields CRM-5362
-    $viewOnlyCustomFields = array();
+    $viewOnlyCustomFields = [];
     foreach ($submitted as $key => $value) {
       $fid = CRM_Core_BAO_CustomField::getKeyID($key);
       if ($fid && array_key_exists($fid, $cFields) && !empty($cFields[$fid]['attributes']['is_view'])
@@ -1782,14 +1875,14 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     }
 
     if (!$checkPermissions || (CRM_Core_Permission::check('merge duplicate contacts') &&
-      CRM_Core_Permission::check('delete contacts'))
+        CRM_Core_Permission::check('delete contacts'))
     ) {
       // if ext id is submitted then set it null for contact to be deleted
       if (!empty($submitted['external_identifier'])) {
         $query = "UPDATE civicrm_contact SET external_identifier = null WHERE id = {$otherId}";
         CRM_Core_DAO::executeQuery($query);
       }
-      civicrm_api3('contact', 'delete', array('id' => $otherId));
+      civicrm_api3('contact', 'delete', ['id' => $otherId]);
     }
 
     // CRM-15681 merge sub_types
@@ -1843,19 +1936,19 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    *   Array of custom table names
    */
   private static function getAffectedCustomTables($customFieldIDs) {
-    $customTableToCopyValues = array();
+    $customTableToCopyValues = [];
 
     foreach ($customFieldIDs as $fieldID) {
       if (!empty($fieldID)) {
-        $customField = civicrm_api3('custom_field', 'getsingle', array(
+        $customField = civicrm_api3('custom_field', 'getsingle', [
           'id' => $fieldID,
           'is_active' => TRUE,
-        ));
+        ]);
         if (!civicrm_error($customField) && !empty($customField['custom_group_id'])) {
-          $customGroup = civicrm_api3('custom_group', 'getsingle', array(
+          $customGroup = civicrm_api3('custom_group', 'getsingle', [
             'id' => $customField['custom_group_id'],
             'is_active' => TRUE,
-          ));
+          ]);
 
           if (!civicrm_error($customGroup) && !empty($customGroup['table_name'])) {
             $customTableToCopyValues[] = $customGroup['table_name'];
@@ -1875,7 +1968,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    */
   public static function getContactFields() {
     $contactFields = CRM_Contact_DAO_Contact::fields();
-    $invalidFields = array(
+    $invalidFields = [
       'api_key',
       'created_date',
       'display_name',
@@ -1885,7 +1978,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       'primary_contact_id',
       'sort_name',
       'user_unique_id',
-    );
+    ];
     foreach ($contactFields as $field => $value) {
       if (in_array($field, $invalidFields)) {
         unset($contactFields[$field]);
@@ -1911,7 +2004,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
     while ($dao->fetch()) {
       $relationshipTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $dao->membership_type_id, 'relationship_type_id', 'id');
       if ($relationshipTypeId) {
-        $membershipParams = array(
+        $membershipParams = [
           'id' => $dao->id,
           'contact_id' => $dao->contact_id,
           'membership_type_id' => $dao->membership_type_id,
@@ -1920,7 +2013,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
           'end_date' => CRM_Utils_Date::isoToMysql($dao->end_date),
           'source' => $dao->source,
           'status_id' => $dao->status_id,
-        );
+        ];
         // create/update membership(s) for related contact(s)
         CRM_Member_BAO_Membership::createRelatedMemberships($membershipParams, $dao);
       } // end of if relationshipTypeId
@@ -1936,28 +2029,31 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @throws \CiviCRM_API3_Exception
    */
   public static function createMergeActivities($mainId, $otherId) {
-    $params = array(
+    $params = [
       1 => $otherId,
       2 => $mainId,
-    );
-    $activity = civicrm_api3('activity', 'create', array(
+    ];
+    $activity = civicrm_api3('activity', 'create', [
       'source_contact_id' => CRM_Core_Session::getLoggedInContactID() ? CRM_Core_Session::getLoggedInContactID() :
-        $mainId,
+      $mainId,
       'subject' => ts('Contact ID %1 has been merged and deleted.', $params),
       'target_contact_id' => $mainId,
       'activity_type_id' => 'Contact Merged',
       'status_id' => 'Completed',
-    ));
-    if (civicrm_api3('Setting', 'getvalue', array('name' => 'contact_undelete', 'group' => 'CiviCRM Preferences'))) {
-      civicrm_api3('activity', 'create', array(
+    ]);
+    if (civicrm_api3('Setting', 'getvalue', [
+      'name' => 'contact_undelete',
+      'group' => 'CiviCRM Preferences',
+    ])) {
+      civicrm_api3('activity', 'create', [
         'source_contact_id' => CRM_Core_Session::getLoggedInContactID() ? CRM_Core_Session::getLoggedInContactID() :
-          $otherId,
+        $otherId,
         'subject' => ts('Contact ID %1 has been merged into Contact ID %2 and deleted.', $params),
         'target_contact_id' => $otherId,
         'activity_type_id' => 'Contact Deleted by Merge',
         'parent_id' => $activity['id'],
         'status_id' => 'Completed',
-      ));
+      ]);
     }
   }
 
@@ -1983,19 +2079,19 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    *   Limit to searching for matches against this many contacts.
    *
    * @return array
-   *    Array of matches meeting the criteria.
+   *   Array of matches meeting the criteria.
    */
-  public static function getDuplicatePairs($rule_group_id, $group_id, $reloadCacheIfEmpty, $batchLimit, $isSelected, $orderByClause = '', $includeConflicts = TRUE, $criteria = array(), $checkPermissions = TRUE, $searchLimit = 0) {
+  public static function getDuplicatePairs($rule_group_id, $group_id, $reloadCacheIfEmpty, $batchLimit, $isSelected, $orderByClause = '', $includeConflicts = TRUE, $criteria = [], $checkPermissions = TRUE, $searchLimit = 0) {
     $where = self::getWhereString($isSelected);
     $cacheKeyString = self::getMergeCacheKeyString($rule_group_id, $group_id, $criteria, $checkPermissions);
     $join = self::getJoinOnDedupeTable();
-    $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, array(), $orderByClause, $includeConflicts);
+    $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, [], $orderByClause, $includeConflicts);
     if (empty($dupePairs) && $reloadCacheIfEmpty) {
       // If we haven't found any dupes, probably cache is empty.
       // Try filling cache and give another try. We don't need to specify include conflicts here are there will not be any
       // until we have done some processing.
       CRM_Core_BAO_PrevNextCache::refillCache($rule_group_id, $group_id, $cacheKeyString, $criteria, $checkPermissions, $searchLimit);
-      $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, array(), $orderByClause, $includeConflicts);
+      $dupePairs = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where, 0, $batchLimit, [], $orderByClause, $includeConflicts);
       return $dupePairs;
     }
     return $dupePairs;
@@ -2015,7 +2111,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    *
    * @return string
    */
-  public static function getMergeCacheKeyString($rule_group_id, $group_id, $criteria = array(), $checkPermissions = TRUE) {
+  public static function getMergeCacheKeyString($rule_group_id, $group_id, $criteria = [], $checkPermissions = TRUE) {
     $contactType = CRM_Dedupe_BAO_RuleGroup::getContactTypeForRuleGroup($rule_group_id);
     $cacheKeyString = "merge_{$contactType}";
     $cacheKeyString .= $rule_group_id ? "_{$rule_group_id}" : '_0';
@@ -2042,23 +2138,23 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    */
   public static function getSpecialValues($contact) {
     $preferred_communication_method = CRM_Utils_Array::value('preferred_communication_method', $contact);
-    $value = empty($preferred_communication_method) ? array() : $preferred_communication_method;
-    $specialValues = array(
+    $value = empty($preferred_communication_method) ? [] : $preferred_communication_method;
+    $specialValues = [
       'preferred_communication_method' => $value,
       'communication_style_id' => $value,
-    );
+    ];
 
     if (!empty($contact['preferred_communication_method'])) {
       // api 3 returns pref_comm_method as an array, which breaks the lookup; so we reconstruct
       $prefCommList = is_array($specialValues['preferred_communication_method']) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $specialValues['preferred_communication_method']) : $specialValues['preferred_communication_method'];
       $specialValues['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
     }
-    $names = array(
-      'preferred_communication_method' => array(
+    $names = [
+      'preferred_communication_method' => [
         'newName' => 'preferred_communication_method_display',
         'groupName' => 'preferred_communication_method',
-      ),
-    );
+      ],
+    ];
     CRM_Core_OptionGroup::lookupValues($specialValues, $names);
 
     if (!empty($contact['communication_style'])) {
@@ -2080,7 +2176,7 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       return \Civi::$statics[__CLASS__]['merge_fields_metadata'];
     }
     $fields = CRM_Contact_DAO_Contact::fields();
-    static $optionValueFields = array();
+    static $optionValueFields = [];
     if (empty($optionValueFields)) {
       $optionValueFields = CRM_Core_OptionValue::getFields();
     }
@@ -2101,18 +2197,18 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
    * @throws CRM_Core_Exception
    */
   public static function getMergeContactDetails($contact_id) {
-    $params = array(
+    $params = [
       'contact_id' => $contact_id,
       'version' => 3,
-      'return' => array_merge(array('display_name'), self::getContactFields()),
-    );
+      'return' => array_merge(['display_name'], self::getContactFields()),
+    ];
     $result = civicrm_api('contact', 'get', $params);
 
     // CRM-18480: Cancel the process if the contact is already deleted
     if (isset($result['values'][$contact_id]['contact_is_deleted']) && !empty($result['values'][$contact_id]['contact_is_deleted'])) {
-      throw new CRM_Core_Exception(ts('Cannot merge because one contact (ID %1) has been deleted.', array(
+      throw new CRM_Core_Exception(ts('Cannot merge because one contact (ID %1) has been deleted.', [
         1 => $contact_id,
-      )));
+      ]));
     }
 
     return $result['values'][$contact_id];
@@ -2163,17 +2259,17 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
       }
       $locBlocks[$fieldName][$fieldCount]['operation'] = $operation;
     }
-    $blocksDAO = array();
+    $blocksDAO = [];
 
     // @todo Handle OpenID (not currently in API).
     if (!empty($locBlocks)) {
       $locationBlocks = self::getLocationBlockInfo();
 
-      $primaryBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, array('is_primary' => 1));
-      $billingBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, array('is_billing' => 1));
+      $primaryBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, ['is_primary' => 1]);
+      $billingBlockIds = CRM_Contact_BAO_Contact::getLocBlockIds($mainId, ['is_billing' => 1]);
 
       foreach ($locBlocks as $name => $block) {
-        $blocksDAO[$name] = array('delete' => array(), 'update' => array());
+        $blocksDAO[$name] = ['delete' => [], 'update' => []];
         if (!is_array($block) || CRM_Utils_System::isNull($block)) {
           continue;
         }
@@ -2282,20 +2378,20 @@ INNER JOIN  civicrm_membership membership2 ON membership1.membership_type_id = m
   protected static function dedupePair(&$migrationInfo, &$resultStats, &$deletedContacts, $mode, $checkPermissions, $mainId, $otherId, $cacheKeyString) {
 
     // go ahead with merge if there is no conflict
-    $conflicts = array();
+    $conflicts = [];
     if (!CRM_Dedupe_Merger::skipMerge($mainId, $otherId, $migrationInfo, $mode, $conflicts)) {
       CRM_Dedupe_Merger::moveAllBelongings($mainId, $otherId, $migrationInfo, $checkPermissions);
-      $resultStats['merged'][] = array(
+      $resultStats['merged'][] = [
         'main_id' => $mainId,
         'other_id' => $otherId,
-      );
+      ];
       $deletedContacts[] = $otherId;
     }
     else {
-      $resultStats['skipped'][] = array(
+      $resultStats['skipped'][] = [
         'main_id' => $mainId,
         'other_id' => $otherId,
-      );
+      ];
     }
 
     // store any conflicts