CRM/Core - Cleanup boolean expressions
[civicrm-core.git] / CRM / Core / PseudoConstant.php
index fbea0cefd51873e91596a1fa255454555329726a..843fd7099e18df563f477cc70ad3591bf2da1e83 100644 (file)
@@ -185,7 +185,7 @@ class CRM_Core_PseudoConstant {
     // Historically this was 'false' but according to the notes in
     // CRM_Core_DAO::buildOptionsContext it should be context dependent.
     // timidly changing for 'search' only to fix world_region in search options.
-    $localizeDefault = in_array($context, ['search']) ? TRUE : FALSE;
+    $localizeDefault = in_array($context, ['search']);
     // Merge params with defaults
     $params += [
       'grouping' => FALSE,
@@ -211,15 +211,15 @@ class CRM_Core_PseudoConstant {
     $dao = new $daoName();
     $fieldSpec = $dao->getFieldSpec($fieldName);
 
-    // Ensure we have the canonical name for this field
-    $fieldName = CRM_Utils_Array::value('name', $fieldSpec, $fieldName);
-
     // Return false if field doesn't exist.
     if (empty($fieldSpec)) {
       return FALSE;
     }
 
-    elseif (!empty($fieldSpec['pseudoconstant'])) {
+    // Ensure we have the canonical name for this field
+    $fieldName = $fieldSpec['name'] ?? $fieldName;
+
+    if (!empty($fieldSpec['pseudoconstant'])) {
       $pseudoconstant = $fieldSpec['pseudoconstant'];
 
       // if callback is specified..
@@ -232,9 +232,9 @@ class CRM_Core_PseudoConstant {
 
       // Merge params with schema defaults
       $params += [
-        'condition' => CRM_Utils_Array::value('condition', $pseudoconstant, []),
-        'keyColumn' => CRM_Utils_Array::value('keyColumn', $pseudoconstant),
-        'labelColumn' => CRM_Utils_Array::value('labelColumn', $pseudoconstant),
+        'condition' => $pseudoconstant['condition'] ?? [],
+        'keyColumn' => $pseudoconstant['keyColumn'] ?? NULL,
+        'labelColumn' => $pseudoconstant['labelColumn'] ?? NULL,
       ];
 
       // Fetch option group from option_value table
@@ -824,7 +824,7 @@ WHERE  id = %1";
         $countryIsoCodes = self::countryIsoCode();
         $defaultID = array_search(CRM_Core_BAO_Country::defaultContactCountry(), $countryIsoCodes);
         if ($defaultID !== FALSE) {
-          $default[$defaultID] = CRM_Utils_Array::value($defaultID, self::$country);
+          $default[$defaultID] = self::$country[$defaultID] ?? NULL;
           self::$country = $default + self::$country;
         }
       }
@@ -1393,7 +1393,7 @@ WHERE  id = %1
     $index = $filter['greeting_type'] . '_' . $columnName;
 
     // also add contactType to the array
-    $contactType = CRM_Utils_Array::value('contact_type', $filter);
+    $contactType = $filter['contact_type'] ?? NULL;
     if ($contactType) {
       $index .= '_' . $contactType;
     }