Merge pull request #16001 from agileware/CIVICRM-1383
[civicrm-core.git] / CRM / Case / BAO / Case.php
index f947784c068b93e06a4bf0c76b162afacf7ae44a..00dbc265ed93e452c147688a82be0ba11926de97 100644 (file)
@@ -1,34 +1,18 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
- |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
 /**
@@ -184,7 +168,7 @@ LEFT JOIN civicrm_case_type ON
   civicrm_case.case_type_id = civicrm_case_type.id
 WHERE civicrm_case.id = %1";
 
-    $queryParams = array(1 => array($caseId, 'Integer'));
+    $queryParams = [1 => [$caseId, 'Integer']];
 
     return CRM_Core_DAO::singleValueQuery($query, $queryParams);
   }
@@ -233,10 +217,10 @@ WHERE civicrm_case.id = %1";
       CRM_Utils_Hook::post('delete', 'Case', $caseId, $case);
 
       // remove case from recent items.
-      $caseRecent = array(
+      $caseRecent = [
         'id' => $caseId,
         'type' => 'Case',
-      );
+      ];
       CRM_Utils_Recent::del($caseRecent);
       return TRUE;
     }
@@ -283,7 +267,7 @@ WHERE civicrm_case.id = %1";
     $caseContact = new CRM_Case_DAO_CaseContact();
     $caseContact->case_id = $caseId;
     $caseContact->find();
-    $contactArray = array();
+    $contactArray = [];
     $count = $startArrayAt;
     while ($caseContact->fetch()) {
       if ($contactID != $caseContact->contact_id) {
@@ -305,14 +289,14 @@ WHERE civicrm_case.id = %1";
   public static function getCaseIdByActivityId($activityId) {
     $originalId = CRM_Core_DAO::singleValueQuery(
       'SELECT original_id FROM civicrm_activity WHERE id = %1',
-      array('1' => array($activityId, 'Integer'))
+      ['1' => [$activityId, 'Integer']]
     );
     $caseId = CRM_Core_DAO::singleValueQuery(
       'SELECT case_id FROM civicrm_case_activity WHERE activity_id in (%1,%2)',
-      array(
-        '1' => array($activityId, 'Integer'),
-        '2' => array($originalId ? $originalId : $activityId, 'Integer'),
-      )
+      [
+        '1' => [$activityId, 'Integer'],
+        '2' => [$originalId ? $originalId : $activityId, 'Integer'],
+      ]
     );
     return $caseId;
   }
@@ -326,7 +310,7 @@ WHERE civicrm_case.id = %1";
    * @return array
    */
   public static function getContactNames($caseId) {
-    $contactNames = array();
+    $contactNames = [];
     if (!$caseId) {
       return $contactNames;
     }
@@ -346,7 +330,7 @@ WHERE civicrm_case.id = %1";
      ORDER BY civicrm_case_contact.id";
 
     $dao = CRM_Core_DAO::executeQuery($query,
-      array(1 => array($caseId, 'Integer'))
+      [1 => [$caseId, 'Integer']]
     );
     while ($dao->fetch()) {
       $contactNames[$dao->cid]['contact_id'] = $dao->cid;
@@ -389,10 +373,10 @@ WHERE cc.contact_id = %1 AND civicrm_case_type.name = '{$caseType}'";
       $query .= " AND ca.is_deleted = 0";
     }
 
-    $params = array(1 => array($contactID, 'Integer'));
+    $params = [1 => [$contactID, 'Integer']];
     $dao = CRM_Core_DAO::executeQuery($query, $params);
 
-    $caseArray = array();
+    $caseArray = [];
     while ($dao->fetch()) {
       $caseArray[] = $dao->id;
     }
@@ -421,7 +405,7 @@ WHERE cc.contact_id = %1 AND civicrm_case_type.name = '{$caseType}'";
    * @return string
    */
   public static function getCaseActivityQuery($type = 'upcoming', $userID, $condition = NULL, $limit = NULL, $order = NULL) {
-    $selectClauses = array(
+    $selectClauses = [
       'civicrm_case.id as case_id',
       'civicrm_case.subject as case_subject',
       'civicrm_contact.id as contact_id',
@@ -437,7 +421,7 @@ WHERE cc.contact_id = %1 AND civicrm_case_type.name = '{$caseType}'";
       "GROUP_CONCAT(DISTINCT IF(case_relationship.contact_id_b = $userID, case_relation_type.label_a_b, case_relation_type.label_b_a) SEPARATOR ', ') as case_role",
       't_act.activity_date_time as activity_date_time',
       't_act.id as activity_id',
-    );
+    ];
 
     $query = CRM_Contact_BAO_Query::appendAnyValueToSelect($selectClauses, 'case_id');
 
@@ -510,9 +494,9 @@ HERESQL;
    * @return array
    *   Array of Cases
    */
-  public static function getCases($allCases = TRUE, $params = array(), $context = 'dashboard', $getCount = FALSE) {
+  public static function getCases($allCases = TRUE, $params = [], $context = 'dashboard', $getCount = FALSE) {
     $condition = NULL;
-    $casesList = array();
+    $casesList = [];
 
     // validate access for own cases.
     if (!self::accessCiviCase()) {
@@ -532,7 +516,7 @@ HERESQL;
       $allCases = FALSE;
     }
 
-    $whereClauses = array('civicrm_case.is_deleted = 0 AND civicrm_contact.is_deleted <> 1');
+    $whereClauses = ['civicrm_case.is_deleted = 0 AND civicrm_contact.is_deleted <> 1'];
 
     if (!$allCases) {
       $whereClauses[] = "(case_relationship.contact_id_b = {$userID} OR case_relationship.contact_id_a = {$userID})";
@@ -542,7 +526,7 @@ HERESQL;
       $whereClauses[] = "civicrm_case.status_id != " . CRM_Core_PseudoConstant::getKey('CRM_Case_BAO_Case', 'case_status_id', 'Closed');
     }
 
-    foreach (array('case_type_id', 'status_id') as $column) {
+    foreach (['case_type_id', 'status_id'] as $column) {
       if (!empty($params[$column])) {
         $whereClauses[] = sprintf("civicrm_case.%s IN (%s)", $column, $params[$column]);
       }
@@ -579,7 +563,7 @@ HERESQL;
     $actions = CRM_Case_Selector_Search::links();
 
     // check is the user has view/edit signer permission
-    $permissions = array(CRM_Core_Permission::VIEW);
+    $permissions = [CRM_Core_Permission::VIEW];
     if (CRM_Core_Permission::check('access all cases and activities') ||
       (!$allCases && CRM_Core_Permission::check('access my cases and activities'))
     ) {
@@ -598,19 +582,19 @@ HERESQL;
 
     foreach ($result->fetchAll() as $case) {
       $key = $case['case_id'];
-      $casesList[$key] = array();
+      $casesList[$key] = [];
       $casesList[$key]['DT_RowId'] = $case['case_id'];
-      $casesList[$key]['DT_RowAttr'] = array('data-entity' => 'case', 'data-id' => $case['case_id']);
+      $casesList[$key]['DT_RowAttr'] = ['data-entity' => 'case', 'data-id' => $case['case_id']];
       $casesList[$key]['DT_RowClass'] = "crm-entity";
 
       $casesList[$key]['activity_list'] = sprintf('<a title="%s" class="crm-expand-row" href="%s"></a>',
         ts('Activities'),
-        CRM_Utils_System::url('civicrm/case/details', array('caseId' => $case['case_id'], 'cid' => $case['contact_id'], 'type' => $type))
+        CRM_Utils_System::url('civicrm/case/details', ['caseId' => $case['case_id'], 'cid' => $case['contact_id'], 'type' => $type])
       );
 
       $phone = empty($case['phone']) ? '' : '<br /><span class="description">' . $case['phone'] . '</span>';
       $casesList[$key]['contact_id'] = sprintf('<a href="%s">%s</a>%s<br /><span class="description">%s: %d</span>',
-        CRM_Utils_System::url('civicrm/contact/view', array('cid' => $case['contact_id'])),
+        CRM_Utils_System::url('civicrm/contact/view', ['cid' => $case['contact_id']]),
         $case['sort_name'],
         $phone,
         ts('Case ID'),
@@ -630,7 +614,7 @@ HERESQL;
         if (self::checkPermission($actId, 'view', $case['activity_type_id'], $userID)) {
           if ($type == 'recent') {
             $casesList[$key]['date'] = sprintf('<a class="action-item crm-hover-button" href="%s" title="%s">%s</a>',
-              CRM_Utils_System::url('civicrm/case/activity/view', array('reset' => 1, 'cid' => $case['contact_id'], 'aid' => $case['activity_id'])),
+              CRM_Utils_System::url('civicrm/case/activity/view', ['reset' => 1, 'cid' => $case['contact_id'], 'aid' => $case['activity_id']]),
               ts('View activity'),
               CRM_Utils_Array::value($case['activity_type_id'], $activityTypeLabels)
             );
@@ -638,8 +622,8 @@ HERESQL;
           else {
             $status = CRM_Utils_Date::overdue($case['activity_date_time']) ? 'status-overdue' : 'status-scheduled';
             $casesList[$key]['date'] = sprintf('<a class="crm-popup %s" href="%s" title="%s">%s</a> &nbsp;&nbsp;',
-             $status,
-              CRM_Utils_System::url('civicrm/case/activity/view', array('reset' => 1, 'cid' => $case['contact_id'], 'aid' => $case['activity_id'])),
+              $status,
+              CRM_Utils_System::url('civicrm/case/activity/view', ['reset' => 1, 'cid' => $case['contact_id'], 'aid' => $case['activity_id']]),
               ts('View activity'),
               CRM_Utils_Array::value($case['activity_type_id'], $activityTypeLabels)
             );
@@ -647,18 +631,18 @@ HERESQL;
         }
         if (isset($case['activity_type_id']) && self::checkPermission($actId, 'edit', $case['activity_type_id'], $userID)) {
           $casesList[$key]['date'] .= sprintf('<a class="action-item crm-hover-button" href="%s" title="%s"><i class="crm-i fa-pencil"></i></a>',
-            CRM_Utils_System::url('civicrm/case/activity', array('reset' => 1, 'cid' => $case['contact_id'], 'caseid' => $case['case_id'], 'action' => 'update', 'id' => $actId)),
+            CRM_Utils_System::url('civicrm/case/activity', ['reset' => 1, 'cid' => $case['contact_id'], 'caseid' => $case['case_id'], 'action' => 'update', 'id' => $actId]),
             ts('Edit activity')
           );
         }
       }
       $casesList[$key]['date'] .= "<br/>" . CRM_Utils_Date::customFormat($case['activity_date_time']);
       $casesList[$key]['links'] = CRM_Core_Action::formLink($actions['primaryActions'], $mask,
-        array(
+        [
           'id' => $case['case_id'],
           'cid' => $case['contact_id'],
           'cxt' => $context,
-        ),
+        ],
         ts('more'),
         FALSE,
         'case.actions.primary',
@@ -674,10 +658,11 @@ HERESQL;
    * Get the summary of cases counts by type and status.
    *
    * @param bool $allCases
+   *
    * @return array
    */
   public static function getCasesSummary($allCases = TRUE) {
-    $caseSummary = array();
+    $caseSummary = [];
 
     //validate access for civicase.
     if (!self::accessCiviCase()) {
@@ -703,7 +688,7 @@ HERESQL;
     }
 
     // build rows with actual data
-    $rows = array();
+    $rows = [];
     $myGroupByClause = $mySelectClause = $myCaseFromClause = $myCaseWhereClauseA = $myCaseWhereClauseB = '';
 
     if ($allCases) {
@@ -756,12 +741,12 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas
         $rows[$res->case_type][$res->case_status]['count'] = $rows[$res->case_type][$res->case_status]['count'] + 1;
       }
       else {
-        $rows[$res->case_type][$res->case_status] = array(
+        $rows[$res->case_type][$res->case_status] = [
           'count' => 1,
           'url' => CRM_Utils_System::url('civicrm/case/search',
             "reset=1&force=1&status={$res->status_id}&type={$res->case_type_id}&case_owner={$case_owner}"
           ),
-        );
+        ];
       }
     }
     $caseSummary['rows'] = array_merge($caseTypes, $rows);
@@ -805,18 +790,18 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas
       $query .= ' AND rel.is_active = 1 AND (rel.end_date IS NULL OR rel.end_date > NOW())';
     }
 
-    $params = array(
-      1 => array($contactID, 'Positive'),
-      2 => array($caseID, 'Positive'),
-    );
+    $params = [
+      1 => [$contactID, 'Positive'],
+      2 => [$caseID, 'Positive'],
+    ];
 
     if ($relationshipID) {
       $query .= ' AND rel.id = %3 ';
-      $params[3] = array($relationshipID, 'Integer');
+      $params[3] = [$relationshipID, 'Integer'];
     }
     $dao = CRM_Core_DAO::executeQuery($query, $params);
 
-    $values = array();
+    $values = [];
     while ($dao->fetch()) {
       $rid = $dao->civicrm_relationship_id;
       $values[$rid]['cid'] = $dao->civicrm_contact_id;
@@ -989,7 +974,7 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas
     $limit = " LIMIT $start, $rp";
 
     $query = $select . $from . $where . $groupBy . $orderBy . $limit;
-    $queryParams = array(1 => array($caseID, 'Integer'));
+    $queryParams = [1 => [$caseID, 'Integer']];
 
     $dao = CRM_Core_DAO::executeQuery($query, $queryParams);
     $caseCount = CRM_Core_DAO::singleValueQuery('SELECT FOUND_ROWS()');
@@ -1041,7 +1026,7 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas
       }
 
       //Add data to the row for inline editing, via DataTable syntax
-      $caseActivities[$caseActivityId]['DT_RowAttr'] = array();
+      $caseActivities[$caseActivityId]['DT_RowAttr'] = [];
       $caseActivities[$caseActivityId]['DT_RowAttr']['data-entity'] = 'activity';
       $caseActivities[$caseActivityId]['DT_RowAttr']['data-id'] = $caseActivityId;
 
@@ -1093,10 +1078,11 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas
         $caseActivity['no_attachments'] = count($attachmentIDs);
       }
 
-      $caseActivities[$caseActivityId]['links'] = CRM_Case_Selector_Search::addCaseActivityLinks($caseID, $contactID, $userID, $context, $dao);
+      $caseActivities[$caseActivityId]['links']
+        = CRM_Case_Selector_Search::addCaseActivityLinks($caseID, $contactID, $userID, $context, $dao);
     }
 
-    $caseActivitiesDT = array();
+    $caseActivitiesDT = [];
     $caseActivitiesDT['data'] = array_values($caseActivities);
     $caseActivitiesDT['recordsTotal'] = $caseCount;
     $caseActivitiesDT['recordsFiltered'] = $caseCount;
@@ -1141,19 +1127,19 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas
    *
    */
   public static function getRelatedContacts($caseID, $includeDetails = TRUE) {
-    $caseRoles = array();
+    $caseRoles = [];
     if ($includeDetails) {
-      $caseInfo = civicrm_api3('Case', 'getsingle', array(
+      $caseInfo = civicrm_api3('Case', 'getsingle', [
         'id' => $caseID,
         // Most efficient way of retrieving definition is to also include case type id and name so the api doesn't have to look it up separately
-        'return' => array('case_type_id', 'case_type_id.name', 'case_type_id.definition', 'contact_id'),
-      ));
+        'return' => ['case_type_id', 'case_type_id.name', 'case_type_id.definition', 'contact_id'],
+      ]);
       if (!empty($caseInfo['case_type_id.definition']['caseRoles'])) {
         $caseRoles = CRM_Utils_Array::rekey($caseInfo['case_type_id.definition']['caseRoles'], 'name');
       }
     }
 
-    $values = array();
+    $values = [];
     $query = <<<HERESQL
     SELECT cc.display_name as name, cc.sort_name as sort_name, cc.id, cr.relationship_type_id, crt.label_b_a as role, crt.name_b_a as role_name, ce.email, cp.phone
     FROM civicrm_relationship cr
@@ -1189,10 +1175,10 @@ SELECT civicrm_case.id, case_status.label AS case_status, status_id, civicrm_cas
      AND cr.is_active
      AND cc.id NOT IN (%2)
 HERESQL;
-    $params = array(
-      1 => array($caseID, 'Integer'),
-      2 => array(implode(',', $caseInfo['client_id']), 'String'),
-    );
+    $params = [
+      1 => [$caseID, 'Integer'],
+      2 => [implode(',', $caseInfo['client_id']), 'String'],
+    ];
     $dao = CRM_Core_DAO::executeQuery($query, $params);
 
     while ($dao->fetch()) {
@@ -1200,7 +1186,7 @@ HERESQL;
         $values[$dao->id] = 1;
       }
       else {
-        $details = array(
+        $details = [
           'contact_id' => $dao->id,
           'display_name' => $dao->name,
           'sort_name' => $dao->sort_name,
@@ -1208,7 +1194,7 @@ HERESQL;
           'role' => $dao->role,
           'email' => $dao->email,
           'phone' => $dao->phone,
-        );
+        ];
         // Add more info about the role (creator, manager)
         $role = CRM_Utils_Array::value($dao->role_name, $caseRoles);
         if ($role) {
@@ -1241,7 +1227,7 @@ HERESQL;
       return FALSE;
     }
 
-    $tplParams = $activityInfo = array();
+    $tplParams = $activityInfo = [];
     $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityId, 'activity_type_id');
     // If it's a case activity
     if ($caseId) {
@@ -1266,7 +1252,7 @@ HERESQL;
 
     $activityInfo = $xmlProcessorReport->getActivityInfo($clientId, $activityId, $anyActivity, $isRedact);
     if ($caseId) {
-      $activityInfo['fields'][] = array('label' => 'Case ID', 'type' => 'String', 'value' => $caseId);
+      $activityInfo['fields'][] = ['label' => 'Case ID', 'type' => 'String', 'value' => $caseId];
     }
     $tplParams['activityTypeName'] = CRM_Core_PseudoConstant::getLabel('CRM_Activity_DAO_Activity', 'activity_type_id', $activityTypeId);
     $tplParams['activity'] = $activityInfo;
@@ -1283,7 +1269,7 @@ HERESQL;
     }
 
     //also create activities simultaneously of this copy.
-    $activityParams = array();
+    $activityParams = [];
 
     $activityParams['source_record_id'] = $activityId;
     $activityParams['source_contact_id'] = $userID;
@@ -1302,11 +1288,11 @@ HERESQL;
       $tplParams['idHash'] = substr(sha1(CIVICRM_SITE_KEY . $caseId), 0, 7);
     }
 
-    $result = array();
+    $result = [];
     // CRM-20308 get receiptFrom defaults see https://issues.civicrm.org/jira/browse/CRM-20308
     $receiptFrom = self::getReceiptFrom($activityId);
 
-    $recordedActivityParams = array();
+    $recordedActivityParams = [];
 
     foreach ($contacts as $mail => $info) {
       $tplParams['contact'] = $info;
@@ -1315,7 +1301,7 @@ HERESQL;
       $displayName = CRM_Utils_Array::value('display_name', $info);
 
       list($result[CRM_Utils_Array::value('contact_id', $info)], $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
-        array(
+        [
           'groupName' => 'msg_tpl_workflow_case',
           'valueName' => 'case_activity',
           'contactId' => CRM_Utils_Array::value('contact_id', $info),
@@ -1324,7 +1310,7 @@ HERESQL;
           'toName' => $displayName,
           'toEmail' => $mail,
           'attachments' => $attachments,
-        )
+        ]
       );
 
       $activityParams['subject'] = ts('%1 - copy sent to %2', [1 => $activitySubject, 2 => $displayName]);
@@ -1354,10 +1340,10 @@ HERESQL;
 
       //create case_activity record if its case activity.
       if ($caseId) {
-        $caseParams = array(
+        $caseParams = [
           'activity_id' => $activity->id,
           'case_id' => $caseId,
-        );
+        ];
         self::processCaseActivity($caseParams);
       }
     }
@@ -1377,10 +1363,10 @@ HERESQL;
    * @return array
    */
   public static function getCaseActivityCount($caseId, $activityTypeId) {
-    $queryParam = array(
-      1 => array($caseId, 'Integer'),
-      2 => array($activityTypeId, 'Integer'),
-    );
+    $queryParam = [
+      1 => [$caseId, 'Integer'],
+      2 => [$activityTypeId, 'Integer'],
+    ];
     $query = "SELECT count(ca.id) as countact
  FROM       civicrm_activity ca
  INNER JOIN civicrm_case_activity cca ON ca.id = cca.activity_id
@@ -1410,7 +1396,7 @@ HERESQL;
       !is_readable($file)
     ) {
       return CRM_Core_Error::fatal(ts('File %1 does not exist or is not readable',
-        array(1 => $file)
+        [1 => $file]
       ));
     }
 
@@ -1430,7 +1416,7 @@ HERESQL;
         //if caseId is invalid, return as error file
         if (!CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'id')) {
           return CRM_Core_Error::createAPIError(ts('Invalid case ID ( %1 ) in TO: field.',
-            array(1 => $caseId)
+            [1 => $caseId]
           ));
         }
       }
@@ -1443,7 +1429,7 @@ HERESQL;
       $contactDetails = self::getRelatedContacts($caseId, FALSE);
 
       if (!empty($contactDetails[$result['from']['id']])) {
-        $params = array();
+        $params = [];
         $params['subject'] = $result['subject'];
         $params['activity_date_time'] = $result['date'];
         $params['details'] = $result['body'];
@@ -1451,7 +1437,7 @@ HERESQL;
         $params['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed');
 
         $details = CRM_Case_PseudoConstant::caseActivityType();
-        $matches = array();
+        $matches = [];
         preg_match('/^\W+([a-zA-Z0-9_ ]+)(\W+)?\n/i',
           $result['body'], $matches
         );
@@ -1469,15 +1455,15 @@ HERESQL;
         // create activity
         $activity = CRM_Activity_BAO_Activity::create($params);
 
-        $caseParams = array(
+        $caseParams = [
           'activity_id' => $activity->id,
           'case_id' => $caseId,
-        );
+        ];
         self::processCaseActivity($caseParams);
       }
       else {
         return CRM_Core_Error::createAPIError(ts('FROM email contact %1 doesn\'t have a relationship to the referenced case.',
-          array(1 => $result['from']['email'])
+          [1 => $result['from']['email']]
         ));
       }
     }
@@ -1512,7 +1498,7 @@ HERESQL;
 
     $res = CRM_Core_DAO::executeQuery($query);
 
-    $activityInfo = array();
+    $activityInfo = [];
     while ($res->fetch()) {
       if ($type == 'upcoming') {
         $activityInfo[$res->case_id]['date'] = $res->activity_date_time;
@@ -1536,19 +1522,19 @@ HERESQL;
   public static function &exportableFields() {
     if (!self::$_exportableFields) {
       if (!self::$_exportableFields) {
-        self::$_exportableFields = array();
+        self::$_exportableFields = [];
       }
 
       $fields = CRM_Case_DAO_Case::export();
-      $fields['case_role'] = array('title' => ts('Role in Case'));
-      $fields['case_type'] = array(
+      $fields['case_role'] = ['title' => ts('Role in Case')];
+      $fields['case_type'] = [
         'title' => ts('Case Type'),
         'name' => 'case_type',
-      );
-      $fields['case_status'] = array(
+      ];
+      $fields['case_status'] = [
         'title' => ts('Case Status'),
         'name' => 'case_status',
-      );
+      ];
 
       // add custom data for cases
       $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Case'));
@@ -1596,21 +1582,21 @@ HERESQL;
    * @return array
    */
   public static function getGlobalContacts(&$groupInfo, $sort = NULL, $showLinks = NULL, $returnOnlyCount = FALSE, $offset = 0, $rowCount = 25) {
-    $globalContacts = array();
+    $globalContacts = [];
 
     $settingsProcessor = new CRM_Case_XMLProcessor_Settings();
     $settings = $settingsProcessor->run();
     if (!empty($settings)) {
       $groupInfo['name'] = $settings['groupname'];
       if ($groupInfo['name']) {
-        $searchParams = array('name' => $groupInfo['name']);
-        $results = array();
+        $searchParams = ['name' => $groupInfo['name']];
+        $results = [];
         CRM_Contact_BAO_Group::retrieve($searchParams, $results);
         if ($results) {
           $groupInfo['id'] = $results['id'];
           $groupInfo['title'] = $results['title'];
-          $params = array(array('group', '=', $groupInfo['id'], 0, 0));
-          $return = array('contact_id' => 1, 'sort_name' => 1, 'display_name' => 1, 'email' => 1, 'phone' => 1);
+          $params = [['group', '=', $groupInfo['id'], 0, 0]];
+          $return = ['contact_id' => 1, 'sort_name' => 1, 'display_name' => 1, 'email' => 1, 'phone' => 1];
           list($globalContacts) = CRM_Contact_BAO_Query::apiQuery($params, $return, NULL, $sort, $offset, $rowCount, TRUE, $returnOnlyCount);
 
           if ($returnOnlyCount) {
@@ -1630,6 +1616,7 @@ HERESQL;
 
   /**
    * Convenience function to get both case contacts and global in one array.
+   *
    * @param int $caseId
    *
    * @return array
@@ -1637,7 +1624,7 @@ HERESQL;
   public static function getRelatedAndGlobalContacts($caseId) {
     $relatedContacts = self::getRelatedContacts($caseId);
 
-    $groupInfo = array();
+    $groupInfo = [];
     $globalContacts = self::getGlobalContacts($groupInfo);
 
     //unset values which are not required.
@@ -1667,8 +1654,8 @@ HERESQL;
    *   case activities due dates
    *
    */
-  public static function getCaseActivityDates($caseID, $criteriaParams = array(), $latestDate = FALSE) {
-    $values = array();
+  public static function getCaseActivityDates($caseID, $criteriaParams = [], $latestDate = FALSE) {
+    $values = [];
     $selectDate = " ca.activity_date_time";
     $where = $groupBy = ' ';
 
@@ -1696,7 +1683,7 @@ HERESQL;
                   LEFT JOIN civicrm_case_activity cca ON cca.activity_id = ca.id LEFT JOIN civicrm_case cc ON cc.id = cca.case_id
                   WHERE cc.id = %1 {$where} {$groupBy}";
 
-    $params = array(1 => array($caseID, 'Integer'));
+    $params = [1 => [$caseID, 'Integer']];
     $dao = CRM_Core_DAO::executeQuery($query, $params);
 
     while ($dao->fetch()) {
@@ -1721,14 +1708,14 @@ HERESQL;
       return;
     }
 
-    $queryParam = array();
+    $queryParam = [];
     if (is_array($relationshipId)) {
       $relationshipId = implode(',', $relationshipId);
       $relationshipClause = " civicrm_relationship.id IN ($relationshipId)";
     }
     else {
       $relationshipClause = " civicrm_relationship.id = %1";
-      $queryParam[1] = array($relationshipId, 'Positive');
+      $queryParam[1] = [$relationshipId, 'Positive'];
     }
 
     $query = "
@@ -1761,12 +1748,12 @@ HERESQL;
     }
 
     $session = CRM_Core_Session::singleton();
-    $activityParams = array(
+    $activityParams = [
       'source_contact_id' => $session->get('userID'),
       'subject' => $caseRelationship . ' : ' . $assigneContactName,
       'activity_date_time' => date('YmdHis'),
       'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Completed'),
-    );
+    ];
 
     //if $relContactId is passed, role is added or modified.
     if (!empty($relContactId)) {
@@ -1782,10 +1769,10 @@ HERESQL;
     $activity = CRM_Activity_BAO_Activity::create($activityParams);
 
     //create case_activity record.
-    $caseParams = array(
+    $caseParams = [
       'activity_id' => $activity->id,
       'case_id' => $caseId,
-    );
+    ];
 
     CRM_Case_BAO_Case::processCaseActivity($caseParams);
   }
@@ -1833,15 +1820,15 @@ HERESQL;
            WHERE civicrm_case.id = %2 AND is_active = 1";
       }
 
-      $managerRoleParams = array(
-        1 => array(substr($managerRoleId, 0, -4), 'Integer'),
-        2 => array($caseId, 'Integer'),
-      );
+      $managerRoleParams = [
+        1 => [substr($managerRoleId, 0, -4), 'Integer'],
+        2 => [$caseId, 'Integer'],
+      ];
 
       $dao = CRM_Core_DAO::executeQuery($managerRoleQuery, $managerRoleParams);
       if ($dao->fetch()) {
         $caseManagerName = sprintf('<a href="%s">%s</a>',
-          CRM_Utils_System::url('civicrm/contact/view', array('cid' => $dao->casemanager_id)),
+          CRM_Utils_System::url('civicrm/contact/view', ['cid' => $dao->casemanager_id]),
           $dao->casemanager
         );
       }
@@ -1857,7 +1844,7 @@ HERESQL;
    * @return int
    */
   public static function caseCount($contactId = NULL, $excludeDeleted = TRUE) {
-    $params = array('check_permissions' => TRUE);
+    $params = ['check_permissions' => TRUE];
     if ($excludeDeleted) {
       $params['is_deleted'] = 0;
     }
@@ -1886,12 +1873,12 @@ HERESQL;
     //FIXME : do check for permissions.
 
     if (!$caseId) {
-      return array();
+      return [];
     }
 
     $linkActType = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Link Cases');
     if (!$linkActType) {
-      return array();
+      return [];
     }
 
     $whereClause = "mainCase.id = %2";
@@ -1908,11 +1895,11 @@ HERESQL;
  INNER JOIN  civicrm_activity relAct           ON (relCaseAct.activity_id = relAct.id  AND relAct.activity_type_id = %1)
      WHERE  $whereClause";
 
-    $dao = CRM_Core_DAO::executeQuery($query, array(
-      1 => array($linkActType, 'Integer'),
-      2 => array($caseId, 'Integer'),
-    ));
-    $relatedCaseIds = array();
+    $dao = CRM_Core_DAO::executeQuery($query, [
+      1 => [$linkActType, 'Integer'],
+      2 => [$caseId, 'Integer'],
+    ]);
+    $relatedCaseIds = [];
     while ($dao->fetch()) {
       $relatedCaseIds[$dao->case_id] = $dao->case_id;
     }
@@ -1931,10 +1918,10 @@ HERESQL;
    */
   public static function getRelatedCases($caseId, $excludeDeleted = TRUE) {
     $relatedCaseIds = self::getRelatedCaseIds($caseId, $excludeDeleted);
-    $relatedCases = array();
+    $relatedCases = [];
 
     if (!$relatedCaseIds) {
-      return array();
+      return [];
     }
 
     $whereClause = 'relCase.id IN ( ' . implode(',', $relatedCaseIds) . ' )';
@@ -1943,7 +1930,7 @@ HERESQL;
     }
 
     //filter for permissioned cases.
-    $filterCases = array();
+    $filterCases = [];
     $doFilterCases = FALSE;
     if (!CRM_Core_Permission::check('access all cases and activities')) {
       $doFilterCases = TRUE;
@@ -1980,13 +1967,13 @@ HERESQL;
         $clientView = "<a href='{$contactViewUrl}{$dao->client_id}'>$dao->client_name</a>";
       }
 
-      $relatedCases[$dao->id] = array(
+      $relatedCases[$dao->id] = [
         'case_id' => $dao->id,
         'case_type' => $dao->case_type,
         'client_name' => $clientView,
         'case_status' => $statuses[$dao->status_id],
         'links' => $caseView,
-      );
+      ];
     }
 
     return $relatedCases;
@@ -1995,12 +1982,13 @@ HERESQL;
   /**
    * Merge two duplicate contacts' cases - follow CRM-5758 rules.
    *
+   * @param int $mainContactId
+   * @param int $otherContactId
+   *
    * @see CRM_Dedupe_Merger::cpTables()
    *
    * TODO: use the 3rd $sqls param to append sql statements rather than executing them here
    *
-   * @param int $mainContactId
-   * @param int $otherContactId
    */
   public static function mergeContacts($mainContactId, $otherContactId) {
     self::mergeCases($mainContactId, NULL, $otherContactId);
@@ -2044,7 +2032,7 @@ HERESQL;
       $duplicateCases = TRUE;
     }
 
-    $mainCaseIds = array();
+    $mainCaseIds = [];
     if (!$duplicateContacts && !$duplicateCases) {
       return $mainCaseIds;
     }
@@ -2056,10 +2044,10 @@ HERESQL;
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
 
-    $processCaseIds = array($otherCaseId);
+    $processCaseIds = [$otherCaseId];
     if ($duplicateContacts && !$duplicateCases) {
       if ($changeClient) {
-        $processCaseIds = array($mainCaseId);
+        $processCaseIds = [$mainCaseId];
       }
       else {
         //get all case ids for other contact.
@@ -2078,7 +2066,7 @@ HERESQL;
     // copy all cases and connect to main contact id.
     foreach ($processCaseIds as $otherCaseId) {
       if ($duplicateContacts) {
-        $mainCase = CRM_Core_DAO::copyGeneric('CRM_Case_DAO_Case', array('id' => $otherCaseId));
+        $mainCase = CRM_Core_DAO::copyGeneric('CRM_Case_DAO_Case', ['id' => $otherCaseId]);
         $mainCaseId = $mainCase->id;
         if (!$mainCaseId) {
           continue;
@@ -2113,11 +2101,11 @@ HERESQL;
       }
 
       // get all activities for other case.
-      $otherCaseActivities = array();
+      $otherCaseActivities = [];
       CRM_Core_DAO::commonRetrieveAll('CRM_Case_DAO_CaseActivity', 'case_id', $otherCaseId, $otherCaseActivities);
 
       //for duplicate cases do not process singleton activities.
-      $otherActivityIds = $singletonActivityIds = array();
+      $otherActivityIds = $singletonActivityIds = [];
       foreach ($otherCaseActivities as $caseActivityId => $otherIds) {
         $otherActId = CRM_Utils_Array::value('activity_id', $otherIds);
         if (!$otherActId || in_array($otherActId, $otherActivityIds)) {
@@ -2140,7 +2128,7 @@ SELECT  id
       }
 
       // migrate all activities and connect to main contact.
-      $copiedActivityIds = $activityMappingIds = array();
+      $copiedActivityIds = $activityMappingIds = [];
       sort($otherActivityIds);
       foreach ($otherActivityIds as $otherActivityId) {
 
@@ -2157,7 +2145,7 @@ SELECT  id
           continue;
         }
 
-        $mainActVals = array();
+        $mainActVals = [];
         $mainActivity = new CRM_Activity_DAO_Activity();
         CRM_Core_DAO::storeValues($otherActivity, $mainActVals);
         $mainActivity->copyValues($mainActVals);
@@ -2250,10 +2238,10 @@ SELECT  id
         }
 
         // copy custom fields and attachments
-        $aparams = array(
+        $aparams = [
           'activityID' => $otherActivityId,
           'mainActivityId' => $mainActivityId,
-        );
+        ];
         CRM_Activity_BAO_Activity::copyExtendedActivityData($aparams);
       }
 
@@ -2263,9 +2251,9 @@ SELECT  id
         $otherRelationship = new CRM_Contact_DAO_Relationship();
         $otherRelationship->case_id = $otherCaseId;
         $otherRelationship->find();
-        $otherRelationshipIds = array();
+        $otherRelationshipIds = [];
         while ($otherRelationship->fetch()) {
-          $otherRelVals = array();
+          $otherRelVals = [];
           $updateOtherRel = FALSE;
           CRM_Core_DAO::storeValues($otherRelationship, $otherRelVals);
 
@@ -2322,28 +2310,28 @@ SELECT  id
 
         $mergeActType = array_search('Reassigned Case', $activityTypes);
         $mergeActSubject = ts("Case %1 reassigned client from %2 to %3. New Case ID is %4.",
-          array(
+          [
             1 => $otherCaseId,
             2 => $otherContactDisplayName,
             3 => $mainContactDisplayName,
             4 => $mainCaseId,
-          )
+          ]
         );
       }
       elseif ($duplicateContacts) {
         $mergeActType = array_search('Merge Case', $activityTypes);
         $mergeActSubject = ts("Case %1 copied from contact id %2 to contact id %3 via merge. New Case ID is %4.",
-          array(
+          [
             1 => $otherCaseId,
             2 => $otherContactId,
             3 => $mainContactId,
             4 => $mainCaseId,
-          )
+          ]
         );
       }
       else {
         $mergeActType = array_search('Merge Case', $activityTypes);
-        $mergeActSubject = ts("Case %1 merged into case %2", array(1 => $otherCaseId, 2 => $mainCaseId));
+        $mergeActSubject = ts("Case %1 merged into case %2", [1 => $otherCaseId, 2 => $mainCaseId]);
         if (!empty($copiedActivityIds)) {
           $sql = '
 SELECT id, subject, activity_date_time, activity_type_id
@@ -2361,14 +2349,14 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       }
 
       // Create merge activity record. Source for merge activity is the logged in user's contact ID ($currentUserId).
-      $activityParams = array(
+      $activityParams = [
         'subject' => $mergeActSubject,
         'details' => $mergeActSubjectDetails,
         'status_id' => $completedActivityStatus,
         'activity_type_id' => $mergeActType,
         'source_contact_id' => $currentUserId,
         'activity_date_time' => date('YmdHis'),
-      );
+      ];
 
       $mergeActivity = CRM_Activity_BAO_Activity::create($activityParams);
       $mergeActivityId = $mergeActivity->id;
@@ -2377,10 +2365,10 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       }
 
       //connect merge activity to case.
-      $mergeCaseAct = array(
+      $mergeCaseAct = [
         'case_id' => $mainCaseId,
         'activity_id' => $mergeActivityId,
-      );
+      ];
 
       self::processCaseActivity($mergeCaseAct);
     }
@@ -2461,23 +2449,23 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
     }
 
     //do check for cases.
-    $caseActOperations = array(
+    $caseActOperations = [
       'File On Case',
       'Link Cases',
       'Move To Case',
       'Copy To Case',
-    );
+    ];
 
     if (in_array($operation, $caseActOperations)) {
       static $caseCount;
       if (!isset($caseCount)) {
         try {
-          $caseCount = civicrm_api3('Case', 'getcount', array(
+          $caseCount = civicrm_api3('Case', 'getcount', [
             'check_permissions' => TRUE,
-            'status_id' => array('!=' => 'Closed'),
+            'status_id' => ['!=' => 'Closed'],
             'is_deleted' => 0,
-            'end_date' => array('IS NULL' => 1),
-          ));
+            'end_date' => ['IS NULL' => 1],
+          ]);
         }
         catch (CiviCRM_API3_Exception $e) {
           // Lack of permissions will throw an exception
@@ -2492,7 +2480,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       }
     }
 
-    $actionOperations = array('view', 'edit', 'delete');
+    $actionOperations = ['view', 'edit', 'delete'];
     if (in_array($operation, $actionOperations)) {
 
       //do cache when user has non/supper permission.
@@ -2508,20 +2496,20 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
         }
 
         //check for permissions.
-        $permissions = array(
-          'view' => array(
+        $permissions = [
+          'view' => [
             'access my cases and activities',
             'access all cases and activities',
-          ),
-          'edit' => array(
+          ],
+          'edit' => [
             'access my cases and activities',
             'access all cases and activities',
-          ),
-          'delete' => array('delete activities'),
-        );
+          ],
+          'delete' => ['delete activities'],
+        ];
 
         //check for core permission.
-        $hasPermissions = array();
+        $hasPermissions = [];
         $checkPermissions = CRM_Utils_Array::value($operation, $permissions);
         if (is_array($checkPermissions)) {
           foreach ($checkPermissions as $per) {
@@ -2534,10 +2522,10 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
         //has permissions.
         if (!empty($hasPermissions)) {
           //need to check activity object specific.
-          if (in_array($operation, array(
+          if (in_array($operation, [
             'view',
             'edit',
-          ))
+          ])
           ) {
             //do we have supper permission.
             if (in_array('access all cases and activities', $hasPermissions[$operation])) {
@@ -2612,7 +2600,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       $actTypeName = CRM_Core_PseudoConstant::getName('CRM_Activity_BAO_Activity', 'activity_type_id', $actTypeId);
 
       //do not allow multiple copy / edit action.
-      $singletonNames = array(
+      $singletonNames = [
         'Open Case',
         'Reassigned Case',
         'Merge Case',
@@ -2620,20 +2608,20 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
         'Assign Case Role',
         'Email',
         'Inbound Email',
-      );
+      ];
 
       //do not allow to delete these activities, CRM-4543
-      $doNotDeleteNames = array('Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date');
+      $doNotDeleteNames = ['Open Case', 'Change Case Type', 'Change Case Status', 'Change Case Start Date'];
 
       //allow edit operation.
-      $allowEditNames = array('Open Case');
+      $allowEditNames = ['Open Case'];
 
       if (CRM_Activity_BAO_Activity::checkEditInboundEmailsPermissions()) {
         $allowEditNames[] = 'Inbound Email';
       }
 
       // do not allow File on Case
-      $doNotFileNames = array(
+      $doNotFileNames = [
         'Open Case',
         'Change Case Type',
         'Change Case Status',
@@ -2642,7 +2630,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
         'Merge Case',
         'Link Cases',
         'Assign Case Role',
-      );
+      ];
 
       if (in_array($actTypeName, $singletonNames)) {
         $allow = FALSE;
@@ -2676,7 +2664,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       //hide Edit link if activity type is NOT editable
       //(special case activities).CRM-5871
       if ($allow && in_array($operation, $actionOperations)) {
-        static $actionFilter = array();
+        static $actionFilter = [];
         if (!array_key_exists($operation, $actionFilter)) {
           $xmlProcessor = new CRM_Case_XMLProcessor_Process();
           $actionFilter[$operation] = $xmlProcessor->get('Settings', 'ActivityTypes', FALSE, $operation);
@@ -2725,9 +2713,9 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       return FALSE;
     }
 
-    $params = array('id' => $caseId, 'check_permissions' => TRUE);
+    $params = ['id' => $caseId, 'check_permissions' => TRUE];
     if ($denyClosed && !CRM_Core_Permission::check('access all cases and activities')) {
-      $params['status_id'] = array('!=' => 'Closed');
+      $params['status_id'] = ['!=' => 'Closed'];
     }
     try {
       return (bool) civicrm_api3('Case', 'getcount', $params);
@@ -2749,7 +2737,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
   public static function isCaseActivity($activityID) {
     $isCaseActivity = FALSE;
     if ($activityID) {
-      $params = array(1 => array($activityID, 'Integer'));
+      $params = [1 => [$activityID, 'Integer']];
       $query = "SELECT id FROM civicrm_case_activity WHERE activity_id = %1";
       if (CRM_Core_DAO::singleValueQuery($query, $params)) {
         $isCaseActivity = TRUE;
@@ -2771,7 +2759,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       $query = "SELECT DISTINCT( civicrm_case.case_type_id ) FROM civicrm_case";
 
       $dao = CRM_Core_DAO::executeQuery($query);
-      $caseTypeIds = array();
+      $caseTypeIds = [];
       while ($dao->fetch()) {
         $typeId = explode(CRM_Core_DAO::VALUE_SEPARATOR,
           $dao->case_type_id
@@ -2795,7 +2783,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       $query = "SELECT DISTINCT( civicrm_case.status_id ) FROM civicrm_case";
 
       $dao = CRM_Core_DAO::executeQuery($query);
-      $caseStatusIds = array();
+      $caseStatusIds = [];
       while ($dao->fetch()) {
         $caseStatusIds[] = $dao->status_id;
       }
@@ -2816,7 +2804,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       $query = "SELECT DISTINCT( civicrm_activity.medium_id )  FROM civicrm_activity";
 
       $dao = CRM_Core_DAO::executeQuery($query);
-      $mediumIds = array();
+      $mediumIds = [];
       while ($dao->fetch()) {
         $mediumIds[] = $dao->medium_id;
       }
@@ -2833,7 +2821,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    * @return array
    */
   public static function isCaseConfigured($contactId = NULL) {
-    $configured = array_fill_keys(array('configured', 'allowToAddNewCase', 'redirectToCaseAdmin'), FALSE);
+    $configured = array_fill_keys(['configured', 'allowToAddNewCase', 'redirectToCaseAdmin'], FALSE);
 
     //lets check for case configured.
     $allCasesCount = CRM_Case_BAO_Case::caseCount(NULL, FALSE);
@@ -2964,11 +2952,11 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
     $caseRelationships = new CRM_Contact_DAO_Relationship();
     $caseRelationships->case_id = $caseId;
     $caseRelationships->find();
-    $relationshipTypes = array();
+    $relationshipTypes = [];
 
     // make sure we don't add duplicate relationships of same relationship type.
     while ($caseRelationships->fetch() && !in_array($caseRelationships->relationship_type_id, $relationshipTypes)) {
-      $values = array();
+      $values = [];
       CRM_Core_DAO::storeValues($caseRelationships, $values);
 
       // add relationship for new client.
@@ -2999,7 +2987,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    *   associated array with client ids
    */
   public static function getCaseClients($caseId) {
-    $clients = array();
+    $clients = [];
     $caseContact = new CRM_Case_DAO_CaseContact();
     $caseContact->case_id = $caseId;
     $caseContact->orderBy('id');
@@ -3017,6 +3005,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    * @param string $direction
    * @param int $cid
    * @param int $relTypeId
+   *
    * @throws \CRM_Core_Exception
    * @throws \CiviCRM_API3_Exception
    */
@@ -3028,35 +3017,38 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
 
     // This case might have multiple clients, so we lookup by relationship instead of by id to get them all
     $sql = "SELECT id FROM civicrm_relationship WHERE case_id = %1 AND contact_id_{$direction} = %2 AND relationship_type_id = %3";
-    $dao = CRM_Core_DAO::executeQuery($sql, array(
-      1 => array($caseId, 'Positive'),
-      2 => array($cid, 'Positive'),
-      3 => array($relTypeId, 'Positive'),
-    ));
+    $dao = CRM_Core_DAO::executeQuery($sql, [
+      1 => [$caseId, 'Positive'],
+      2 => [$cid, 'Positive'],
+      3 => [$relTypeId, 'Positive'],
+    ]);
     while ($dao->fetch()) {
-      civicrm_api3('relationship', 'create', array(
+      civicrm_api3('relationship', 'create', [
         'id' => $dao->id,
         'is_active' => 0,
         'end_date' => 'now',
-      ));
+      ]);
     }
   }
 
   /**
    * Get options for a given case field.
-   * @see CRM_Core_DAO::buildOptions
    *
    * @param string $fieldName
    * @param string $context
-   * @see CRM_Core_DAO::buildOptionsContext
    * @param array $props
    *   Whatever is known about this dao object.
    *
    * @return array|bool
+   * @throws \CiviCRM_API3_Exception
+   *
+   * @see CRM_Core_DAO::buildOptionsContext
+   * @see CRM_Core_DAO::buildOptions
+   *
    */
-  public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+  public static function buildOptions($fieldName, $context = NULL, $props = []) {
     $className = __CLASS__;
-    $params = array();
+    $params = [];
     switch ($fieldName) {
       // This field is not part of this object but the api supports it
       case 'medium_id':
@@ -3067,7 +3059,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       case 'status_id':
         if (!empty($props['case_type_id'])) {
           $idField = is_numeric($props['case_type_id']) ? 'id' : 'name';
-          $caseType = civicrm_api3('CaseType', 'getsingle', array($idField => $props['case_type_id'], 'return' => 'definition'));
+          $caseType = civicrm_api3('CaseType', 'getsingle', [$idField => $props['case_type_id'], 'return' => 'definition']);
           if (!empty($caseType['definition']['statuses'])) {
             $params['condition'] = 'v.name IN ("' . implode('","', $caseType['definition']['statuses']) . '")';
           }
@@ -3083,11 +3075,11 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
   public function addSelectWhereClause() {
     // We always return an array with these keys, even if they are empty,
     // because this tells the query builder that we have considered these fields for acls
-    $clauses = array(
-      'id' => array(),
+    $clauses = [
+      'id' => [],
       // Only case admins can view deleted cases
-      'is_deleted' => CRM_Core_Permission::check('administer CiviCase') ? array() : array("= 0"),
-    );
+      'is_deleted' => CRM_Core_Permission::check('administer CiviCase') ? [] : ["= 0"],
+    ];
     // Ensure the user has permission to view the case client
     $contactClause = CRM_Utils_SQL::mergeSubquery('Contact');
     if ($contactClause) {
@@ -3118,6 +3110,8 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    * @param int $activityID
    *
    * @return mixed $emailFromContactId
+   *
+   * @throws \CiviCRM_API3_Exception
    * @see https://issues.civicrm.org/jira/browse/CRM-20308
    */
   public static function getReceiptFrom($activityID) {
@@ -3128,11 +3122,11 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
       //    so we can disable this behaviour with the "allow_mail_from_logged_in_contact" setting.
       // There is always a 'Added by' contact for a activity,
       //  so we can safely use ActivityContact.Getvalue API
-      $sourceContactId = civicrm_api3('ActivityContact', 'getvalue', array(
+      $sourceContactId = civicrm_api3('ActivityContact', 'getvalue', [
         'activity_id' => $activityID,
         'record_type_id' => 'Activity Source',
         'return' => 'contact_id',
-      ));
+      ]);
       list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($sourceContactId);
     }
 
@@ -3174,7 +3168,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
    */
   public static function getCaseRoleDirection($caseId, $roleTypeId = NULL) {
     try {
-      $case = civicrm_api3('Case', 'getsingle', array('id' => $caseId));
+      $case = civicrm_api3('Case', 'getsingle', ['id' => $caseId]);
     }
     catch (CiviCRM_API3_Exception $e) {
       // Lack of permissions will throw an exception
@@ -3182,18 +3176,18 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
     }
     if (!empty($case['case_type_id'])) {
       try {
-        $caseType = civicrm_api3('CaseType', 'getsingle', array('id' => $case['case_type_id'], 'return' => array('definition')));
+        $caseType = civicrm_api3('CaseType', 'getsingle', ['id' => $case['case_type_id'], 'return' => ['definition']]);
       }
       catch (CiviCRM_API3_Exception $e) {
         // Lack of permissions will throw an exception
         return 'no case type found';
       }
       if (!empty($caseType['definition']['caseRoles'])) {
-        $caseRoles = array();
+        $caseRoles = [];
         foreach ($caseType['definition']['caseRoles'] as $key => $roleDetails) {
           // Check if its an a_b label
           try {
-            $relType = civicrm_api3('RelationshipType', 'getsingle', array('label_a_b' => $roleDetails['name']));
+            $relType = civicrm_api3('RelationshipType', 'getsingle', ['label_a_b' => $roleDetails['name']]);
           }
           catch (CiviCRM_API3_Exception $e) {
           }
@@ -3203,7 +3197,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
           }
           // Check if its a b_a label
           try {
-            $relTypeBa = civicrm_api3('RelationshipType', 'getsingle', array('label_b_a' => $roleDetails['name']));
+            $relTypeBa = civicrm_api3('RelationshipType', 'getsingle', ['label_b_a' => $roleDetails['name']]);
           }
           catch (CiviCRM_API3_Exception $e) {
           }