Fix php notices in php dashboard code
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 14 Sep 2023 23:12:57 +0000 (11:12 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 14 Sep 2023 23:14:20 +0000 (11:14 +1200)
CRM/Contact/Page/View/UserDashBoard.php
CRM/PCP/BAO/PCP.php

index dcadcc71ef47b19bfbbfe89d23449cd5884b2106..c93b161213f37a2b5f606ab07e8578d3d7a6d07d 100644 (file)
@@ -19,7 +19,7 @@
  * This class is used to build User Dashboard
  */
 class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page {
-  public $_contactId = NULL;
+  public $_contactId;
 
   /**
    * Always show public groups.
@@ -34,7 +34,7 @@ class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page {
    *
    * @var array
    */
-  public static $_links = NULL;
+  public static $_links;
 
   /**
    * @throws Exception
@@ -149,7 +149,7 @@ class CRM_Contact_Page_View_UserDashBoard extends CRM_Core_Page {
         'sectionTitle' => ts('Personal Campaign Pages'),
         'weight' => 40,
       ];
-      list($pcpBlock, $pcpInfo) = CRM_PCP_BAO_PCP::getPcpDashboardInfo($this->_contactId);
+      [$pcpBlock, $pcpInfo] = CRM_PCP_BAO_PCP::getPcpDashboardInfo((int) $this->_contactId);
       $this->assign('pcpBlock', $pcpBlock);
       $this->assign('pcpInfo', $pcpInfo);
     }
index 72a059a708d7c7c1d62a65ce8430784055a28efc..3f78c95392422c5259126f490252cc7d2b94fc46 100644 (file)
@@ -73,12 +73,13 @@ WHERE  civicrm_pcp.contact_id = civicrm_contact.id
   /**
    * Return PCP  Block info for dashboard.
    *
-   * @param int $contactId
+   * @param int $contactID
    *
    * @return array
    *   array of Pcp if found
+   * @throws \Civi\Core\Exception\DBQueryException
    */
-  public static function getPcpDashboardInfo($contactId) {
+  public static function getPcpDashboardInfo(int $contactID): array {
     $query = '
 SELECT pcp.*, block.is_tellfriend_enabled,
 COALESCE(cp.end_date, event.end_date) as end_date
@@ -90,16 +91,15 @@ WHERE pcp.is_active = 1
   AND pcp.contact_id = %1
 ORDER BY page_type, page_id';
 
-    $params = [1 => [$contactId, 'Integer']];
-    $pcpInfoDao = CRM_Core_DAO::executeQuery($query, $params);
+    $pcpInfoDao = CRM_Core_DAO::executeQuery($query, [1 => [$contactID, 'Integer']]);
 
     $approved = CRM_Core_PseudoConstant::getKey('CRM_PCP_BAO_PCP', 'status_id', 'Approved');
     $contactPCPPages = [];
     $pcpInfo = [];
-
+    $links = [];
     while ($pcpInfoDao->fetch()) {
       $links = self::pcpLinks($pcpInfoDao->id);
-      $hide = $mask = array_sum(array_keys($links['all']));
+      $hide = array_sum(array_keys($links['all']));
       $mask = $hide;
       if ($links) {
         $replace = [
@@ -180,8 +180,8 @@ ORDER BY target_entity_type, target_entity_id
           'pageComponent' => $pcpBlockDao->target_entity_type,
         ];
       }
-      $pcpLink = $links['add'];
-      $action = CRM_Core_Action::formLink($pcpLink, $mask, $replace, ts('more'),
+      $pcpLink = $links['add'] ?? NULL;
+      $action = CRM_Core_Action::formLink($pcpLink, $mask, $replace ?? [], ts('more'),
         FALSE, 'pcp.dashboard.other', "{$pcpBlockDao->target_entity_type}_PCP", $pcpBlockDao->target_entity_id);
       $pageTitle = self::getPcpTitle($pcpBlockDao->target_entity_type, (int) $pcpBlockDao->target_entity_id);
       if ($pageTitle) {
@@ -666,7 +666,7 @@ WHERE pcp.id = %1 AND cc.contribution_status_id = %2 AND cc.is_test = 0";
     ];
 
     //get the default domain email address.
-    list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
+    [$domainEmailName, $domainEmailAddress] = CRM_Core_BAO_Domain::getNameAndEmail();
 
     if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
       $fixUrl = CRM_Utils_System::url('civicrm/admin/options/from_email_address', 'reset=1');
@@ -678,10 +678,10 @@ WHERE pcp.id = %1 AND cc.contribution_status_id = %2 AND cc.is_test = 0";
     // get recipient (supporter) name and email
     $params = ['id' => $pcpId];
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
-    list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($pcpInfo['contact_id']);
+    [$name, $address] = CRM_Contact_BAO_Contact_Location::getEmailDetails($pcpInfo['contact_id']);
 
     // get pcp block info
-    list($blockId, $eid) = self::getPcpBlockEntityId($pcpId, $component);
+    [$blockId, $eid] = self::getPcpBlockEntityId($pcpId, $component);
     $params = ['id' => $blockId];
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo);
 
@@ -712,7 +712,7 @@ WHERE pcp.id = %1 AND cc.contribution_status_id = %2 AND cc.is_test = 0";
 
     $tplName = $isInitial ? 'pcp_supporter_notify' : 'pcp_status_change';
 
-    list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(
+    [$sent, $subject, $message, $html] = CRM_Core_BAO_MessageTemplate::sendTemplate(
       [
         'groupName' => 'msg_tpl_workflow_contribution',
         'workflow' => $tplName,