From 63d7640448cd41cda34b2851ffa5408e01748fa0 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 17 Mar 2020 19:34:12 -0400 Subject: [PATCH] CRM/Core - Cleanup boolean expressions --- CRM/Core/Action.php | 2 +- CRM/Core/BAO/ActionLog.php | 2 +- CRM/Core/BAO/CMSUser.php | 8 ++++---- CRM/Core/BAO/ConfigSetting.php | 2 +- CRM/Core/BAO/CustomGroup.php | 6 +++--- CRM/Core/BAO/CustomValueTable.php | 2 +- CRM/Core/BAO/Domain.php | 4 ++-- CRM/Core/BAO/SchemaHandler.php | 3 +-- CRM/Core/BAO/StatusPreference.php | 2 +- CRM/Core/BAO/UFGroup.php | 4 ++-- CRM/Core/BAO/WordReplacement.php | 2 +- CRM/Core/Component/Info.php | 2 +- CRM/Core/DAO.php | 13 ++++++------- CRM/Core/Error.php | 2 +- CRM/Core/Key.php | 2 +- CRM/Core/Menu.php | 2 +- CRM/Core/OptionValue.php | 2 +- CRM/Core/Payment.php | 4 ++-- CRM/Core/Permission.php | 4 ++-- CRM/Core/PseudoConstant.php | 2 +- 20 files changed, 34 insertions(+), 36 deletions(-) diff --git a/CRM/Core/Action.php b/CRM/Core/Action.php index 52f7c78cf2..a5e7ef11d3 100644 --- a/CRM/Core/Action.php +++ b/CRM/Core/Action.php @@ -216,7 +216,7 @@ class CRM_Core_Action { if (!$mask || !array_key_exists('bit', $link) || ($mask & $link['bit'])) { $extra = isset($link['extra']) ? self::replace($link['extra'], $values) : NULL; - $frontend = (isset($link['fe'])) ? TRUE : FALSE; + $frontend = isset($link['fe']); if (isset($link['qs']) && !CRM_Utils_System::isNull($link['qs'])) { $urlPath = CRM_Utils_System::url(self::replace($link['url'], $values), diff --git a/CRM/Core/BAO/ActionLog.php b/CRM/Core/BAO/ActionLog.php index 7615b97249..c04e3f30cc 100644 --- a/CRM/Core/BAO/ActionLog.php +++ b/CRM/Core/BAO/ActionLog.php @@ -36,7 +36,7 @@ class CRM_Core_BAO_ActionLog extends CRM_Core_DAO_ActionLog { $actionLog->copyValues($params); - $edit = ($actionLog->id) ? TRUE : FALSE; + $edit = (bool) $actionLog->id; if ($edit) { CRM_Utils_Hook::pre('edit', 'ActionLog', $actionLog->id, $actionLog); } diff --git a/CRM/Core/BAO/CMSUser.php b/CRM/Core/BAO/CMSUser.php index c09e557e15..aecd30c4b0 100644 --- a/CRM/Core/BAO/CMSUser.php +++ b/CRM/Core/BAO/CMSUser.php @@ -72,8 +72,8 @@ class CRM_Core_BAO_CMSUser { $showCMS = FALSE; $isDrupal = $config->userSystem->is_drupal; - $isJoomla = ucfirst($config->userFramework) == 'Joomla' ? TRUE : FALSE; - $isWordPress = $config->userFramework == 'WordPress' ? TRUE : FALSE; + $isJoomla = ucfirst($config->userFramework) == 'Joomla'; + $isWordPress = $config->userFramework == 'WordPress'; if (!$config->userSystem->isUserRegistrationPermitted()) { // Do not build form if CMS is not configured to allow creating users. @@ -148,8 +148,8 @@ class CRM_Core_BAO_CMSUser { $config = CRM_Core_Config::singleton(); $isDrupal = $config->userSystem->is_drupal; - $isJoomla = ucfirst($config->userFramework) == 'Joomla' ? TRUE : FALSE; - $isWordPress = $config->userFramework == 'WordPress' ? TRUE : FALSE; + $isJoomla = ucfirst($config->userFramework) == 'Joomla'; + $isWordPress = $config->userFramework == 'WordPress'; $errors = []; if ($isDrupal || $isJoomla || $isWordPress) { diff --git a/CRM/Core/BAO/ConfigSetting.php b/CRM/Core/BAO/ConfigSetting.php index e011e4e884..11450b6813 100644 --- a/CRM/Core/BAO/ConfigSetting.php +++ b/CRM/Core/BAO/ConfigSetting.php @@ -128,7 +128,7 @@ class CRM_Core_BAO_ConfigSetting { */ public static function applyLocale($settings, $activatedLocales) { // are we in a multi-language setup? - $multiLang = $activatedLocales ? TRUE : FALSE; + $multiLang = (bool) $activatedLocales; // set the current language $chosenLocale = NULL; diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index bf77e25106..7e2232a069 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -273,7 +273,7 @@ class CRM_Core_BAO_CustomGroup extends CRM_Core_DAO_CustomGroup { $escapedValue = CRM_Core_DAO::VALUE_SEPARATOR . CRM_Core_DAO::escapeString($columnValue) . CRM_Core_DAO::VALUE_SEPARATOR; $dao->whereAdd("extends_entity_column_value LIKE \"%$escapedValue%\""); //$dao->extends_entity_column_value = $columnValue; - return $dao->find() ? TRUE : FALSE; + return (bool) $dao->find(); } /** @@ -673,7 +673,7 @@ ORDER BY civicrm_custom_group.weight, if ($getCount) { return $recordExists; } - return $recordExists ? TRUE : FALSE; + return (bool) $recordExists; } /** @@ -2103,7 +2103,7 @@ SELECT civicrm_custom_group.id as groupID, civicrm_custom_group.title as groupT public static function hasReachedMaxLimit($customGroupId, $entityId) { // check whether the group is multiple $isMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'is_multiple'); - $isMultiple = ($isMultiple) ? TRUE : FALSE; + $isMultiple = (bool) $isMultiple; $hasReachedMax = FALSE; if ($isMultiple && ($maxMultiple = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'max_multiple')) diff --git a/CRM/Core/BAO/CustomValueTable.php b/CRM/Core/BAO/CustomValueTable.php index a34c49784b..1fa9a508a8 100644 --- a/CRM/Core/BAO/CustomValueTable.php +++ b/CRM/Core/BAO/CustomValueTable.php @@ -473,7 +473,7 @@ AND $cond } $fields[$dao->table_name][] = $dao->fieldID; $select[$dao->table_name][] = "{$dao->column_name} AS custom_{$dao->fieldID}"; - $isMultiple[$dao->table_name] = $dao->is_multiple ? TRUE : FALSE; + $isMultiple[$dao->table_name] = (bool) $dao->is_multiple; $file[$dao->table_name][$dao->fieldID] = $dao->fieldDataType; } diff --git a/CRM/Core/BAO/Domain.php b/CRM/Core/BAO/Domain.php index c9bdb689ea..e01a624d97 100644 --- a/CRM/Core/BAO/Domain.php +++ b/CRM/Core/BAO/Domain.php @@ -150,7 +150,7 @@ class CRM_Core_BAO_Domain extends CRM_Core_DAO_Domain { $numberDomains = CRM_Core_DAO::singleValueQuery($query); $session->set('numberDomains', $numberDomains); } - return $numberDomains > 1 ? TRUE : FALSE; + return $numberDomains > 1; } /** @@ -240,7 +240,7 @@ class CRM_Core_BAO_Domain extends CRM_Core_DAO_Domain { */ public static function isDomainGroup($groupId) { $domainGroupID = self::getGroupId(); - return $domainGroupID == $groupId ? TRUE : FALSE; + return $domainGroupID == (bool) $groupId; } /** diff --git a/CRM/Core/BAO/SchemaHandler.php b/CRM/Core/BAO/SchemaHandler.php index 2f3f70241e..c6757015f0 100644 --- a/CRM/Core/BAO/SchemaHandler.php +++ b/CRM/Core/BAO/SchemaHandler.php @@ -585,8 +585,7 @@ MODIFY {$columnName} varchar( $length ) public static function checkIfFieldExists($tableName, $columnName, $i18nRewrite = TRUE) { $query = "SHOW COLUMNS FROM $tableName LIKE '%1'"; $dao = CRM_Core_DAO::executeQuery($query, [1 => [$columnName, 'Alphanumeric']], TRUE, NULL, FALSE, $i18nRewrite); - $result = $dao->fetch() ? TRUE : FALSE; - return $result; + return (bool) $dao->fetch(); } /** diff --git a/CRM/Core/BAO/StatusPreference.php b/CRM/Core/BAO/StatusPreference.php index c09308f04f..2f225ee9fe 100644 --- a/CRM/Core/BAO/StatusPreference.php +++ b/CRM/Core/BAO/StatusPreference.php @@ -59,7 +59,7 @@ class CRM_Core_BAO_StatusPreference extends CRM_Core_DAO_StatusPreference { $statusPreference->copyValues($params); - $edit = ($statusPreference->id) ? TRUE : FALSE; + $edit = (bool) $statusPreference->id; if ($edit) { CRM_Utils_Hook::pre('edit', 'StatusPreference', $statusPreference->id, $statusPreference); } diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 97342efc22..d420b57e5b 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -1804,7 +1804,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) $rule = $field['rule']; $view = $field['is_view']; $required = ($mode == CRM_Profile_Form::MODE_SEARCH) ? FALSE : $field['is_required']; - $search = ($mode == CRM_Profile_Form::MODE_SEARCH) ? TRUE : FALSE; + $search = $mode == CRM_Profile_Form::MODE_SEARCH; $isShared = CRM_Utils_Array::value('is_shared', $field, 0); // do not display view fields in drupal registration form @@ -2573,7 +2573,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) } } - $validProfile = (empty($required)) ? TRUE : FALSE; + $validProfile = (empty($required)); } return $validProfile; diff --git a/CRM/Core/BAO/WordReplacement.php b/CRM/Core/BAO/WordReplacement.php index e5e215a46c..d8fe9df6b3 100644 --- a/CRM/Core/BAO/WordReplacement.php +++ b/CRM/Core/BAO/WordReplacement.php @@ -232,7 +232,7 @@ WHERE domain_id = %1 $localCustomData = $localeCustomArray[$lang]; // Traverse status array "enabled" "disabled" foreach ($localCustomData as $status => $matchTypes) { - $params["is_active"] = ($status == "enabled") ? TRUE : FALSE; + $params["is_active"] = $status == "enabled"; // Traverse Match Type array "wildcardMatch" "exactMatch" foreach ($matchTypes as $matchType => $words) { $params["match_type"] = $matchType; diff --git a/CRM/Core/Component/Info.php b/CRM/Core/Component/Info.php index 5106a0f99f..33dabe3639 100644 --- a/CRM/Core/Component/Info.php +++ b/CRM/Core/Component/Info.php @@ -305,7 +305,7 @@ abstract class CRM_Core_Component_Info { * true if component needs search integration */ public function usesSearch() { - return $this->info['search'] ? TRUE : FALSE; + return (bool) $this->info['search']; } /** diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 0075a25361..992f950108 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -821,7 +821,7 @@ class CRM_Core_DAO extends DB_DataObject { } if ($object->find(TRUE)) { - return ($daoID && $object->id == $daoID) ? TRUE : FALSE; + return $daoID && $object->id == $daoID; } else { return TRUE; @@ -920,7 +920,7 @@ class CRM_Core_DAO extends DB_DataObject { $show[$tableName] = $dao->Create_Table; } - return preg_match("/\b$constraint\b/i", $show[$tableName]) ? TRUE : FALSE; + return (bool) preg_match("/\b$constraint\b/i", $show[$tableName]); } /** @@ -947,7 +947,7 @@ class CRM_Core_DAO extends DB_DataObject { $show[$tableName] = $dao->Create_Table; } - $result = preg_match("/\bCONSTRAINT\b\s/i", $show[$tableName]) ? TRUE : FALSE; + $result = (bool) preg_match("/\bCONSTRAINT\b\s/i", $show[$tableName]); if ($result == TRUE) { continue; } @@ -985,7 +985,7 @@ class CRM_Core_DAO extends DB_DataObject { } $constraint = "`FK_{$tableName}_{$columnName}`"; $pattern = "/\bCONSTRAINT\b\s+%s\s+\bFOREIGN\s+KEY\b\s/i"; - return preg_match(sprintf($pattern, $constraint), $show[$tableName]) ? TRUE : FALSE; + return (bool) preg_match(sprintf($pattern, $constraint), $show[$tableName]); } /** @@ -1037,8 +1037,7 @@ LIKE %1 $params = [1 => [$tableName, 'String']]; $dao = CRM_Core_DAO::executeQuery($query, $params); - $result = $dao->fetch() ? TRUE : FALSE; - return $result; + return (bool) $dao->fetch(); } /** @@ -1064,7 +1063,7 @@ SELECT version FROM civicrm_domain "; $dbVersion = CRM_Core_DAO::singleValueQuery($query); - return trim($version) == trim($dbVersion) ? TRUE : FALSE; + return trim($version) == trim($dbVersion); } /** diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index d059e81830..a36bb5ce7d 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -730,7 +730,7 @@ class CRM_Core_Error extends PEAR_ErrorStack { $className = isset($trace['class']) ? ($trace['class'] . $trace['type']) : ''; // Do not show args for a few password related functions - $skipArgs = ($className == 'DB::' && $fnName == 'connect') ? TRUE : FALSE; + $skipArgs = $className == 'DB::' && $fnName == 'connect'; if (!empty($trace['args'])) { foreach ($trace['args'] as $arg) { diff --git a/CRM/Core/Key.php b/CRM/Core/Key.php index 382c65f86e..83317ac149 100644 --- a/CRM/Core/Key.php +++ b/CRM/Core/Key.php @@ -135,7 +135,7 @@ class CRM_Core_Key { } // ensure that hash is a 32 digit hex number - return preg_match('#[0-9a-f]{32}#i', $hash) ? TRUE : FALSE; + return (bool) preg_match('#[0-9a-f]{32}#i', $hash); } } diff --git a/CRM/Core/Menu.php b/CRM/Core/Menu.php index 20593b0b28..5ec868771e 100644 --- a/CRM/Core/Menu.php +++ b/CRM/Core/Menu.php @@ -216,7 +216,7 @@ class CRM_Core_Menu { ); $fieldsPresent = array(); foreach ($fieldsToPropagate as $field) { - $fieldsPresent[$field] = CRM_Utils_Array::value($field, $menu[$path]) !== NULL ? TRUE : FALSE; + $fieldsPresent[$field] = isset($menu[$path][$field]); } $args = explode('/', $path); diff --git a/CRM/Core/OptionValue.php b/CRM/Core/OptionValue.php index b7cabfa8e5..27581b35cb 100644 --- a/CRM/Core/OptionValue.php +++ b/CRM/Core/OptionValue.php @@ -261,7 +261,7 @@ class CRM_Core_OptionValue { } if ($object->find(TRUE)) { - return ($daoID && $object->id == $daoID) ? TRUE : FALSE; + return $daoID && $object->id == $daoID; } else { return TRUE; diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 40718337d6..96770b3cdf 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -354,7 +354,7 @@ abstract class CRM_Core_Payment { * @return bool */ protected function supportsLiveMode() { - return empty($this->_paymentProcessor['is_test']) ? TRUE : FALSE; + return empty($this->_paymentProcessor['is_test']); } /** @@ -363,7 +363,7 @@ abstract class CRM_Core_Payment { * @return bool */ protected function supportsTestMode() { - return empty($this->_paymentProcessor['is_test']) ? FALSE : TRUE; + return !empty($this->_paymentProcessor['is_test']); } /** diff --git a/CRM/Core/Permission.php b/CRM/Core/Permission.php index 5c3bf571e8..3cce2d04c4 100644 --- a/CRM/Core/Permission.php +++ b/CRM/Core/Permission.php @@ -278,7 +278,7 @@ class CRM_Core_Permission { } $groups = self::ufGroup($type); - return !empty($groups) && in_array($gid, $groups) ? TRUE : FALSE; + return !empty($groups) && in_array($gid, $groups); } /** @@ -1627,7 +1627,7 @@ class CRM_Core_Permission { * @return bool */ public static function isMultisiteEnabled() { - return Civi::settings()->get('is_enabled') ? TRUE : FALSE; + return (bool) Civi::settings()->get('is_enabled'); } /** diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index c179a8a4a9..843fd7099e 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -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, -- 2.25.1