Skip to content

Commit

Permalink
Merge pull request #16819 from eileenmcnaughton/array
Browse files Browse the repository at this point in the history
[REF] Simplify obtuse boolean expressions
  • Loading branch information
eileenmcnaughton authored Mar 17, 2020
2 parents 48bca06 + 1699214 commit cd06192
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CRM/ACL/BAO/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Civi/Test/GenericAssertionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
7 changes: 1 addition & 6 deletions api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions api/v3/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/v3/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit cd06192

Please sign in to comment.