From b1ff97ebc9cd4152a120ded0c56763c1a06a1798 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 9 Jan 2020 16:08:15 +1300 Subject: [PATCH] [REF] Minor code simplification in dedupe. This just tweaks readability by 1) adding a variable for a value nested fairly deeply in an array 2) removing the foundField handling in favour of a ternary since it's kinda confusing as is --- CRM/Dedupe/Merger.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CRM/Dedupe/Merger.php b/CRM/Dedupe/Merger.php index f6a2e4749e..26d2a12e4d 100644 --- a/CRM/Dedupe/Merger.php +++ b/CRM/Dedupe/Merger.php @@ -1354,25 +1354,24 @@ INNER JOIN civicrm_membership membership2 ON membership1.membership_type_id = m ); foreach ($otherTree as $gid => $group) { - $foundField = FALSE; if (!isset($group['fields'])) { continue; } foreach ($group['fields'] as $fid => $field) { + $mainContactValue = $mainTree[$gid]['fields'][$fid]['customValue'] ?? NULL; + $otherContactValue = $otherTree[$gid]['fields'][$fid]['customValue'] ?? NULL; if (in_array($fid, $compareFields['custom'])) { - if (!$foundField) { - $rows["custom_group_$gid"]['title'] = $group['title']; - $foundField = TRUE; - } - if (!empty($mainTree[$gid]['fields'][$fid]['customValue'])) { - foreach ($mainTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) { + $rows["custom_group_$gid"]['title'] = $rows["custom_group_$gid"]['title'] ?? $group['title']; + + if ($mainContactValue) { + foreach ($mainContactValue as $valueId => $values) { $rows["move_custom_$fid"]['main'] = CRM_Core_BAO_CustomField::displayValue($values['data'], $fid); } } - $value = "null"; - if (!empty($otherTree[$gid]['fields'][$fid]['customValue'])) { - foreach ($otherTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) { + $value = 'null'; + if ($otherContactValue) { + foreach ($otherContactValue as $valueId => $values) { $rows["move_custom_$fid"]['other'] = CRM_Core_BAO_CustomField::displayValue($values['data'], $fid); if ($values['data'] === 0 || $values['data'] === '0') { $values['data'] = $qfZeroBug; -- 2.25.1