[REF] Minor parameter simplification
authorEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 15 Dec 2021 01:52:58 +0000 (14:52 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Wed, 15 Dec 2021 03:09:24 +0000 (16:09 +1300)
The only value in this array used in the function is 'custom' which should be an array. I think it woul
d only ever be an array or NULL (which would then be an array with this change) but I left
a deprecation notice in case. Pass-by-ref isn't needed

CRM/Contact/BAO/Relationship.php

index c4aa4de85e1ed573fecf3da467b9e773d8b7ef4c..4c968676babb97f807b25df7db30ca1d33c6370a 100644 (file)
@@ -979,8 +979,7 @@ WHERE  relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer');
     $relationship = CRM_Core_DAO::executeQuery($queryString);
     while ($relationship->fetch()) {
       // Check whether the custom field values are identical.
-      $result = self::checkDuplicateCustomFields($params, $relationship->id);
-      if ($result) {
+      if (self::checkDuplicateCustomFields($params['custom'] ?? [], $relationship->id)) {
         return TRUE;
       }
     }
@@ -992,23 +991,27 @@ WHERE  relationship_type_id = " . CRM_Utils_Type::escape($type, 'Integer');
    * the same as the values of the custom fields of the relation with given
    * $relationshipId.
    *
-   * @param array $params (reference) an assoc array of name/value pairs
+   * @param array $params an assoc array of name/value pairs
    * @param int $relationshipId ID of an existing duplicate relation
    *
    * @return boolean true if custom field values are identical
    * @access private
    * @static
    */
-  private static function checkDuplicateCustomFields(&$params, $relationshipId) {
+  private static function checkDuplicateCustomFields($params, $relationshipId) {
     // Get the custom values of the existing relationship.
     $existingValues = CRM_Core_BAO_CustomValueTable::getEntityValues($relationshipId, 'Relationship');
     // Create a similar array for the new relationship.
     $newValues = [];
-    if (isset($params['custom']) && is_array($params['custom'])) {
-      // $params['custom'] seems to be an array. Each value is again an array.
+    if (!is_array($params)) {
+      // No idea when this would happen....
+      CRM_Core_Error::deprecatedWarning('params should be an array');
+    }
+    else {
+      // $params seems to be an array, as it should be. Each value is again an array.
       // This array contains one value (key -1), and this value seems to be
       // an array with the information about the custom value.
-      foreach ($params['custom'] as $value) {
+      foreach ($params as $value) {
         foreach ($value as $customValue) {
           $newValues[$customValue['custom_field_id']] = $customValue['value'];
         }