From a02672cc487fe2802ca0e3af742aa37d700d667b Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 17 Jan 2020 14:35:43 +1300 Subject: [PATCH] [NFC] Code cleanup Throw exception rather than fatal - declare exceptions - single quotes - strict comparisons --- CRM/Contact/BAO/GroupNestingCache.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/CRM/Contact/BAO/GroupNestingCache.php b/CRM/Contact/BAO/GroupNestingCache.php index 597cf66a4670..5ef00f1246aa 100644 --- a/CRM/Contact/BAO/GroupNestingCache.php +++ b/CRM/Contact/BAO/GroupNestingCache.php @@ -19,12 +19,12 @@ class CRM_Contact_BAO_GroupNestingCache { /** * Update cache. * - * @throws \Exception + * @throws \CRM_Core_Exception */ public static function update() { // lets build the tree in memory first - $sql = " + $sql = ' SELECT n.child_group_id as child , n.parent_group_id as parent FROM civicrm_group_nesting n, @@ -32,7 +32,7 @@ public static function update() { civicrm_group gp WHERE n.child_group_id = gc.id AND n.parent_group_id = gp.id -"; +'; $dao = CRM_Core_DAO::executeQuery($sql); @@ -57,15 +57,15 @@ public static function update() { } if (self::checkCyclicGraph($tree)) { - CRM_Core_Error::fatal(ts("We detected a cycle which we can't handle. aborting")); + throw new CRM_Core_Exception(ts('We detected a cycle which we can\'t handle. aborting')); } // first reset the current cache entries - $sql = " + $sql = ' UPDATE civicrm_group SET parents = null, children = null -"; +'; CRM_Core_DAO::executeQuery($sql); $values = []; @@ -132,9 +132,10 @@ public static function isCyclic(&$tree, $id) { /** * @param int $id - * @param $groups + * @param array $groups * * @return array + * @throws \CRM_Core_Exception */ public static function getPotentialCandidates($id, &$groups) { $tree = Civi::cache('groups')->get('nestable tree hierarchy'); @@ -201,6 +202,8 @@ public static function getAll(&$all, &$tree, $id, $token) { /** * @return string + * + * @throws \CRM_Core_Exception */ public static function json() { $tree = Civi::cache('groups')->get('nestable tree hierarchy');