Skip to content

Commit

Permalink
[REF] - Simplify redundant calls to empty() function
Browse files Browse the repository at this point in the history
The `empty()` function will automatically handle the case where the first part
of the expression is not set, so there's no need to add an extra call to `empty()`.
  • Loading branch information
colemanw committed Feb 11, 2025
1 parent 07cdd0c commit a3aee71
Show file tree
Hide file tree
Showing 22 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CRM/Admin/Form/WordReplacements.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function postProcess() {
for ($i = 1; $i <= $this->_numStrings; $i++) {
if (!empty($params['new'][$i]) && !empty($params['old'][$i])) {
if (isset($params['enabled']) && !empty($params['enabled'][$i])) {
if (!empty($params['cb']) && !empty($params['cb'][$i])) {
if (!empty($params['cb'][$i])) {
$enabled['exactMatch'] += [$params['old'][$i] => $params['new'][$i]];
}
else {
Expand Down
4 changes: 1 addition & 3 deletions CRM/Contact/BAO/ProximityQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,7 @@ public static function process(&$query, &$values) {
$qill = [];
foreach ($proximityVars as $var => $recordQill) {
$proximityValues = $query->getWhereValues("prox_{$var}", $grouping);
if (!empty($proximityValues) &&
!empty($proximityValues[2])
) {
if (!empty($proximityValues[2])) {
$proximityAddress[$var] = $proximityValues[2];
if ($recordQill) {
$qill[] = $proximityValues[2];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Edit/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharin
}

$entityId = NULL;
if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
if (!empty($form->_values['address'][$blockId])) {
$entityId = $form->_values['address'][$blockId]['id'];
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4016,7 +4016,7 @@ public static function updateMembershipBasedOnCompletionOfContribution($contribu
->addOrderBy('id', 'DESC')
->execute()
->first();
if (!empty($preChangeMembership) && !empty($preChangeMembership['membership_type_id'])) {
if (!empty($preChangeMembership['membership_type_id'])) {
$membershipParams['membership_type_id'] = $preChangeMembership['membership_type_id'];
}
if (empty($membership['end_date']) || (int) $membership['status_id'] !== CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Pending')) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public static function recurringContribution($form): void {
break;
}
// If data has been entered for a recurring field, tell the tpl layer to open the pane
if (!empty($form->_formValues) && !empty($form->_formValues[$key . '_relative']) || !empty($form->_formValues[$key . '_low']) || !empty($form->_formValues[$key . '_high'])) {
if (!empty($form->_formValues[$key . '_relative']) || !empty($form->_formValues[$key . '_low']) || !empty($form->_formValues[$key . '_high'])) {
$form->assign('contribution_recur_pane_open', TRUE);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function initializeDashlets() {
$defaultDashlets = [];
$defaults = ['blog' => 1, 'getting-started' => '0'];
foreach ($defaults as $name => $column) {
if (!empty($allDashlets[$name]) && !empty($allDashlets[$name]['id'])) {
if (!empty($allDashlets[$name]['id'])) {
$defaultDashlets[$name] = [
'dashboard_id' => $allDashlets[$name]['id'],
'is_active' => 1,
Expand Down
1 change: 0 additions & 1 deletion CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2355,7 +2355,6 @@ public static function setProfileDefaults(
else {
if (is_array($details)) {
if ($fieldName === 'url'
&& !empty($details['website'])
&& !empty($details['website'][$locTypeId])
) {
$defaults[$fldName] = $details['website'][$locTypeId]['url'] ?? NULL;
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Payment/ProcessorForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function preProcess($form) {
CRM_Core_Error::statusBounce(ts('Payment processor is not set for this page'));
}

if (!empty($form->_membershipBlock) && !empty($form->_membershipBlock['is_separate_payment']) &&
if (!empty($form->_membershipBlock['is_separate_payment']) &&
(!empty($form->_paymentProcessor['class_name']) &&
!$paymentObject->supports('MultipleConcurrentPayments')
)
Expand All @@ -130,7 +130,7 @@ public static function buildQuickForm($form): void {
// because payment processor is not selected
$processorId = $form->getPaymentProcessorID();
$billing_profile_id = CRM_Utils_Request::retrieve('billing_profile_id', 'String');
if (!empty($form->_values) && !empty($form->_values['is_billing_required'])) {
if (!empty($form->_values['is_billing_required'])) {
$billing_profile_id = 'billing';
}
if (!empty($processorId)) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2578,7 +2578,7 @@ protected static function addLocationFieldInfo($mainId, $otherId, $blockInfo, $b

// Now, build the table rows appropriately, based off the information on
// the 'other' contact
if (!empty($locations['other']) && !empty($locations['other'][$blockName])) {
if (!empty($locations['other'][$blockName])) {
foreach ($locations['other'][$blockName] as $count => $value) {

$displayValue = $value[$blockInfo['displayField']];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/ManageEvent/Fee.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ public function postProcess() {
if (!empty($value['is_default'])) {
$fieldParams['default_option'] = $value['weight'];
}
if (!empty($discountFieldIDs[$j]) && !empty($discountFieldIDs[$j][$value['weight']])) {
if (!empty($discountFieldIDs[$j][$value['weight']])) {
$fieldParams['option_id'][$value['weight']] = $discountFieldIDs[$j][$value['weight']];
unset($discountFieldIDs[$j][$value['weight']]);
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Event/Form/Registration/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function preProcess() {
$this->assign('confirm_text', $this->getEventValue('confirm_text'));
CRM_Utils_Hook::eventDiscount($this, $this->_params);

if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
if (!empty($this->_params[0]['discount']['applied'])) {
$this->set('hookDiscount', $this->_params[0]['discount']);
}
$this->assign('hookDiscount', $this->_params[0]['discount'] ?? '');
Expand Down Expand Up @@ -403,7 +403,7 @@ public function postProcess() {

// if a discount has been applied, lets now deduct it from the amount
// and fix the fee level
if (!empty($this->_params[0]['discount']) && !empty($this->_params[0]['discount']['applied'])) {
if (!empty($this->_params[0]['discount']['applied'])) {
foreach ($this->_params as $k => $v) {
if (($this->_params[$k]['amount'] ?? NULL) > 0 && !empty($this->_params[$k]['discountAmount'])) {
$this->_params[$k]['amount'] -= $this->_params[$k]['discountAmount'];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Controller/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $mod
if ($mid && $continue) {
//CRM-15979 - check if abtest exist for mailing then redirect accordingly
$abtest = CRM_Mailing_BAO_MailingAB::getABTest($mid);
if (!empty($abtest) && !empty($abtest->id)) {
if (!empty($abtest->id)) {
$redirect = CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Page/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function run() {
$this->_mailing_id = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
//CRM-15979 - check if abtest exist for mailing then redirect accordingly
$abtest = CRM_Mailing_BAO_MailingAB::getABTest($this->_mailing_id);
if (!empty($abtest) && !empty($abtest->id)) {
if (!empty($abtest->id)) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/abtest/' . $abtest->id));
}
// check that the user has permission to access mailing id
Expand Down
2 changes: 1 addition & 1 deletion CRM/Price/BAO/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static function create(&$params) {
throw new CRM_Core_Exception($e->getMessage());
}
}
elseif (!empty($optionsIds) && !empty($optionsIds['id'])) {
elseif (!empty($optionsIds['id'])) {
$optionsLoad = civicrm_api3('price_field_value', 'get', ['id' => $optionsIds['id']]);
$options = $optionsLoad['values'][$optionsIds['id']];
$options['is_active'] = $params['is_active'] ?? 1;
Expand Down
3 changes: 1 addition & 2 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2820,8 +2820,7 @@ public function select() {
continue;
}

if (!empty($this->_params['group_bys']) &&
!empty($this->_params['group_bys'][$fieldName]) &&
if (!empty($this->_params['group_bys'][$fieldName]) &&
!empty($this->_params['group_bys_freq'])
) {
switch ($this->_params['group_bys_freq'][$fieldName] ?? NULL) {
Expand Down
4 changes: 2 additions & 2 deletions CRM/Report/Form/Contribute/Lybunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,15 @@ public function statistics(&$rows) {
// Perhaps that works on some other report? But here it just seems odd.
$this->countStat($statistics, count($rows));
if (!empty($rows)) {
if (!empty($this->rollupRow) && !empty($this->rollupRow['civicrm_contribution_last_year_total_amount'])) {
if (!empty($this->rollupRow['civicrm_contribution_last_year_total_amount'])) {
$statistics['counts']['civicrm_contribution_last_year_total_amount'] = [
'value' => $this->rollupRow['civicrm_contribution_last_year_total_amount'],
'title' => $this->getLastYearColumnTitle(),
'type' => CRM_Utils_Type::T_MONEY,
];

}
if (!empty($this->rollupRow) && !empty($this->rollupRow['civicrm_contribution_civicrm_life_time_total'])) {
if (!empty($this->rollupRow['civicrm_contribution_civicrm_life_time_total'])) {
$statistics['counts']['civicrm_contribution_civicrm_life_time_total'] = [
'value' => $this->rollupRow['civicrm_contribution_civicrm_life_time_total'],
'title' => ts('Total LifeTime'),
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function getTypeAttributes(SimpleXMLElement $fieldXML) {
*/
public static function getSize(SimpleXMLElement $fieldXML): string {
// Extract from <size> tag if supplied
if (!empty($fieldXML->html) && !empty($fieldXML->html->size)) {
if (!empty($fieldXML->html->size)) {
return (string) $fieldXML->html->size;
}
return self::getDefaultSize(self::toString('length', $fieldXML));
Expand Down
4 changes: 2 additions & 2 deletions api/class.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function __construct($config = NULL) {
$this->local = TRUE;
$this->input = [];
$this->lastResult = new stdClass();
if (!empty($config) && !empty($config['server'])) {
if (!empty($config['server'])) {
// we are calling a remote server via REST
$this->local = FALSE;
$this->uri = $config['server'];
Expand All @@ -207,7 +207,7 @@ public function __construct($config = NULL) {
$this->useragent = !empty($config['useragent']) ? $config['useragent'] : 'curl';
return;
}
if (!empty($config) && !empty($config['conf_path'])) {
if (!empty($config['conf_path'])) {
if (!defined('CIVICRM_SETTINGS_PATH')) {
define('CIVICRM_SETTINGS_PATH', $config['conf_path'] . '/civicrm.settings.php');
}
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ function civicrm_api3_case_getList($params) {
require_once 'api/v3/Generic/Getlist.php';
require_once 'api/v3/CaseContact.php';
//CRM:19956 - Assign case_id param if both id and case_id is passed to retrieve the case
if (!empty($params['id']) && !empty($params['params']) && !empty($params['params']['case_id'])) {
if (!empty($params['id']) && !empty($params['params']['case_id'])) {
$params['params']['case_id'] = ['IN' => $params['id']];
unset($params['id']);
}
Expand Down
2 changes: 1 addition & 1 deletion api/v3/CaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function civicrm_api3_case_type_create($params) {
* case types keyed by id
*/
function civicrm_api3_case_type_get($params) {
if (!empty($params['options']) && !empty($params['options']['is_count'])) {
if (!empty($params['options']['is_count'])) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
$caseTypes = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function civicrm_api3_domain_get($params) {
if (!empty($params['current_domain'])) {
$params['id'] = CRM_Core_Config::domainID();
}
if (!empty($params['options']) && !empty($params['options']['is_count'])) {
if (!empty($params['options']['is_count'])) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}

Expand Down
2 changes: 1 addition & 1 deletion ext/flexmailer/src/Listener/OpenTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function onCompose(ComposeBatchEvent $e) {
/** @var \Civi\FlexMailer\FlexMailerTask $task */
$mailParams = $task->getMailParams();

if (!empty($mailParams) && !empty($mailParams['html'])) {
if (!empty($mailParams['html'])) {
$openUrl = \CRM_Utils_System::externUrl('extern/open', 'q=' . $task->getEventQueueId());
$mailParams['html'] .= "\n" . '<img src="' . htmlentities($openUrl) . "\" width='1' height='1' alt='' border='0'>";

Expand Down

0 comments on commit a3aee71

Please sign in to comment.