[REF] remove unnecessary variable variables
authoreileen <emcnaughton@wikimedia.org>
Tue, 21 Jul 2020 04:17:42 +0000 (16:17 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 21 Jul 2020 04:17:42 +0000 (16:17 +1200)
For a brief but terrifying spell this arvo I delved into this function to try to understand
the purpose of 'preserveDBName'. Obviously I ran screaming from the room but I thought I could disarm these
few lines to slighly file down the fangs of the beast.

Code is heavily covered by tests

CRM/Contact/BAO/Individual.php

index 679e9229f50fb2f3088581c06924aa26904ab2dd..af28e7a244d5cda5570e3edc681d275be87cc79f 100644 (file)
@@ -50,9 +50,9 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
     }
 
     $sortName = $displayName = '';
-    $firstName = CRM_Utils_Array::value('first_name', $params, '');
-    $middleName = CRM_Utils_Array::value('middle_name', $params, '');
-    $lastName = CRM_Utils_Array::value('last_name', $params, '');
+    $firstName = trim($params['first_name'] ?? '');
+    $middleName = trim($params['middle_name'] ?? '');
+    $lastName = trim($params['last_name'] ?? '');
     $nickName = CRM_Utils_Array::value('nick_name', $params, '');
     $prefix_id = CRM_Utils_Array::value('prefix_id', $params, '');
     $suffix_id = CRM_Utils_Array::value('suffix_id', $params, '');
@@ -162,11 +162,6 @@ class CRM_Contact_BAO_Individual extends CRM_Contact_DAO_Contact {
       }
     }
 
-    //first trim before further processing.
-    foreach (['lastName', 'firstName', 'middleName'] as $fld) {
-      $$fld = trim($$fld);
-    }
-
     if ($lastName || $firstName || $middleName) {
       // make sure we have values for all the name fields.
       $formatted = $params;