[REF] Simplify obtuse boolean expressions
authoreileen <emcnaughton@wikimedia.org>
Tue, 17 Mar 2020 03:05:29 +0000 (16:05 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 17 Mar 2020 03:05:42 +0000 (16:05 +1300)
Partial of https://github.com/civicrm/civicrm-core/pull/16814

I've reviewed this handful  & will merge on pass

CRM/ACL/BAO/ACL.php
Civi/Test/GenericAssertionsTrait.php
api/api.php
api/v3/Contact.php
api/v3/Profile.php
install/index.php

index e0577e8f1d905f446707de0caa542b5778bc9daf..a76081f8df3140bffd29f67568e402771096dd67 100644 (file)
@@ -423,7 +423,7 @@ SELECT count( a.id )
     $params = [1 => [$str, 'String']];
 
     $count = CRM_Core_DAO::singleValueQuery($query, $params);
-    return ($count) ? TRUE : FALSE;
+    return (bool) $count;
   }
 
   /**
index 993e1278cbbb3eb93817929e9b13868ef1809655..fe31b74b139b9af4b4d8fa729b456af7ff2d45ad 100644 (file)
@@ -89,7 +89,7 @@ trait GenericAssertionsTrait {
    * @param array $list
    */
   public function assertArrayKeyExists($key, &$list) {
-    $result = isset($list[$key]) ? TRUE : FALSE;
+    $result = isset($list[$key]);
     $this->assertTrue($result, sprintf("%s element exists?", $key));
   }
 
index 7cbc5d180dcb56f88b29b805d538a6e4bcaaf1fc..cbb4856f4cbaa4514e55b290c6bc93b5e4849a6e 100644 (file)
@@ -184,12 +184,7 @@ function _civicrm_api3_api_getfields(&$apiRequest) {
  *   true if error, false otherwise
  */
 function civicrm_error($result) {
-  if (is_array($result)) {
-    return (array_key_exists('is_error', $result) &&
-      $result['is_error']
-    ) ? TRUE : FALSE;
-  }
-  return FALSE;
+  return is_array($result) && !empty($result['is_error']);
 }
 
 /**
index d79910a4c73282781d66fb23f9973fed9aa7c80f..66b1ae921568479859080340377306ee01dc826e 100644 (file)
@@ -459,8 +459,8 @@ function civicrm_api3_contact_delete($params) {
   if ($contactID == $session->get('userID')) {
     return civicrm_api3_create_error('This contact record is linked to the currently logged in user account - and cannot be deleted.');
   }
-  $restore = !empty($params['restore']) ? $params['restore'] : FALSE;
-  $skipUndelete = !empty($params['skip_undelete']) ? $params['skip_undelete'] : FALSE;
+  $restore = !empty($params['restore']);
+  $skipUndelete = !empty($params['skip_undelete']);
 
   // CRM-12929
   // restrict permanent delete if a contact has financial trxn associated with it
index 17463bb1a3a003cd5446567da43ca658b0bc71d7..ff73c62c615cdd033d88a8faeba7337195419ed9 100644 (file)
@@ -36,7 +36,7 @@
  * @throws API_Exception
  */
 function civicrm_api3_profile_get($params) {
-  $nonStandardLegacyBehaviour = is_numeric($params['profile_id']) ? TRUE : FALSE;
+  $nonStandardLegacyBehaviour = is_numeric($params['profile_id']);
   if (!empty($params['check_permissions']) && !empty($params['contact_id']) && !1 === civicrm_api3('contact', 'getcount', ['contact_id' => $params['contact_id'], 'check_permissions' => 1])) {
     throw new API_Exception('permission denied');
   }
@@ -296,7 +296,7 @@ function _civicrm_api3_profile_submit_spec(&$params, $apirequest) {
     //@todo get_options should take an array - @ the moment it is only takes 'all' - which is supported
     // by other getfields fn
     // we don't resolve state, country & county for performance reasons
-    $resolveOptions = CRM_Utils_Array::value('get_options', $apirequest['params']) == 'all' ? TRUE : FALSE;
+    $resolveOptions = ($apirequest['params']['get_options'] ?? NULL) == 'all';
     $profileID = _civicrm_api3_profile_getProfileID($apirequest['params']['profile_id']);
     $params = _civicrm_api3_buildprofile_submitfields($profileID, $resolveOptions, CRM_Utils_Array::value('cache_clear', $params));
   }
index 585cea24ac0112f1630ee3039f728031395c1451..c7d3a341e586758a54be40eb243c91d046602262 100644 (file)
@@ -517,7 +517,7 @@ class InstallRequirements {
           )
         );
       }
-      $onlyRequire = ($dbName == 'Drupal' || $dbName == 'Backdrop') ? TRUE : FALSE;
+      $onlyRequire = $dbName == 'Drupal' || $dbName == 'Backdrop';
       $this->requireDatabaseOrCreatePermissions(
         $databaseConfig['server'],
         $databaseConfig['username'],