From 581a9d2e388fb3cb25cd995a1c4e7249b8b330d3 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 15 Jul 2021 10:45:21 +1200 Subject: [PATCH] Use type hinting for id This clarifies that the id must be an integer (0 for anonymous) Function is only called from one place --- CRM/ACL/BAO/ACL.php | 5 +++-- CRM/ACL/BAO/Cache.php | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index ea6bdd257d..e9ecf99847 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -91,11 +91,12 @@ class CRM_ACL_BAO_ACL extends CRM_ACL_DAO_ACL { * * @throws \CRM_Core_Exception */ - public static function getAllByContact(?int $contact_id): array { + public static function getAllByContact(int $contact_id): array { $result = []; /* First, the contact-specific ACLs, including ACL Roles */ - if ($contact_id) { + // 0 would be the anonymous contact. + if ($contact_id > 0) { $query = " SELECT acl.* FROM civicrm_acl acl WHERE acl.entity_table = 'civicrm_contact' diff --git a/CRM/ACL/BAO/Cache.php b/CRM/ACL/BAO/Cache.php index af12925101..e022de9c81 100644 --- a/CRM/ACL/BAO/Cache.php +++ b/CRM/ACL/BAO/Cache.php @@ -24,9 +24,11 @@ class CRM_ACL_BAO_Cache extends CRM_ACL_DAO_ACLCache { /** * Build an array of ACLs for a specific ACLed user + * * @param int $id - contact_id of the ACLed user * * @return mixed + * @throws \CRM_Core_Exception */ public static function &build($id) { if (!self::$_cache) { @@ -44,7 +46,7 @@ class CRM_ACL_BAO_Cache extends CRM_ACL_DAO_ACLCache { return self::$_cache[$id]; } - self::$_cache[$id] = CRM_ACL_BAO_ACL::getAllByContact($id); + self::$_cache[$id] = CRM_ACL_BAO_ACL::getAllByContact((int) $id); self::store($id, self::$_cache[$id]); return self::$_cache[$id]; } -- 2.25.1