From 1699214f9e0f41456d228aad4622e0778430a777 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 17 Mar 2020 16:05:29 +1300 Subject: [PATCH] [REF] Simplify obtuse boolean expressions Partial of https://github.com/civicrm/civicrm-core/pull/16814 I've reviewed this handful & will merge on pass --- CRM/ACL/BAO/ACL.php | 2 +- Civi/Test/GenericAssertionsTrait.php | 2 +- api/api.php | 7 +------ api/v3/Contact.php | 4 ++-- api/v3/Profile.php | 4 ++-- install/index.php | 2 +- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index e0577e8f1d90..a76081f8df31 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -423,7 +423,7 @@ public static function check($str, $contactID) { $params = [1 => [$str, 'String']]; $count = CRM_Core_DAO::singleValueQuery($query, $params); - return ($count) ? TRUE : FALSE; + return (bool) $count; } /** diff --git a/Civi/Test/GenericAssertionsTrait.php b/Civi/Test/GenericAssertionsTrait.php index 993e1278cbbb..fe31b74b139b 100644 --- a/Civi/Test/GenericAssertionsTrait.php +++ b/Civi/Test/GenericAssertionsTrait.php @@ -89,7 +89,7 @@ public function assertAttributesEquals($expectedValues, $actualValues, $message * @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)); } diff --git a/api/api.php b/api/api.php index 7cbc5d180dcb..cbb4856f4cba 100644 --- a/api/api.php +++ b/api/api.php @@ -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']); } /** diff --git a/api/v3/Contact.php b/api/v3/Contact.php index d79910a4c732..66b1ae921568 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -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 diff --git a/api/v3/Profile.php b/api/v3/Profile.php index 17463bb1a3a0..ff73c62c615c 100644 --- a/api/v3/Profile.php +++ b/api/v3/Profile.php @@ -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)); } diff --git a/install/index.php b/install/index.php index 585cea24ac01..c7d3a341e586 100644 --- a/install/index.php +++ b/install/index.php @@ -517,7 +517,7 @@ public function checkdatabase($databaseConfig, $dbName) { ) ); } - $onlyRequire = ($dbName == 'Drupal' || $dbName == 'Backdrop') ? TRUE : FALSE; + $onlyRequire = $dbName == 'Drupal' || $dbName == 'Backdrop'; $this->requireDatabaseOrCreatePermissions( $databaseConfig['server'], $databaseConfig['username'],