Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Simplify obtuse boolean expressions #16822

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Activity/Import/Parser/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function summary(&$values) {
// Date-Format part ends.

// Checking error in custom data.
$params['contact_type'] = isset($this->_contactType) ? $this->_contactType : 'Activity';
$params['contact_type'] = $this->_contactType ?? 'Activity';

CRM_Contact_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage);

Expand Down
2 changes: 1 addition & 1 deletion CRM/Badge/BAO/Badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public static function buildBadges(&$params, &$form) {
$query->convertToPseudoNames($dao);
$rows[$dao->participant_id] = [];
foreach ($returnProperties as $key => $dontCare) {
$value = isset($dao->$key) ? $dao->$key : NULL;
$value = $dao->$key ?? NULL;
// Format custom fields
if (strstr($key, 'custom_') && isset($value)) {
$value = CRM_Core_BAO_CustomField::displayValue($value, substr($key, 7), $dao->contact_id);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/Form/Petition/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public function postProcess() {
// array_values($this->_contactProfileFields)[0] but it's PHP 5.4+ only.
$slice = array_slice($this->_contactProfileFields, 0, 1);
$firstField = array_shift($slice);
$addToGroupID = isset($firstField['add_to_group_id']) ? $firstField['add_to_group_id'] : NULL;
$addToGroupID = $firstField['add_to_group_id'] ?? NULL;
$this->_contactId = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_contactProfileFields,
$this->_contactId, $addToGroupID,
$this->_contactProfileId, $this->_ctype,
Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function processVoterData() {
$activityParams['skipRecentView'] = 1;
$activityParams['activity_date_time'] = date('YmdHis');
$activityParams['activity_type_id'] = $activityTypeId;
$activityParams['campaign_id'] = isset($surveyValues['campaign_id']) ? $surveyValues['campaign_id'] : NULL;
$activityParams['campaign_id'] = $surveyValues['campaign_id'] ?? NULL;

$activity = CRM_Activity_BAO_Activity::create($activityParams);
if ($activity->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 @@ -4438,7 +4438,7 @@ public static function isSingleLineItem($id) {
* @throws \CiviCRM_API3_Exception
*/
public static function completeOrder($input, &$ids, $objects, $transaction, $contribution, $isPostPaymentCreate = FALSE) {
$primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id;
$primaryContributionID = $contribution->id ?? $objects['first_contribution']->id;
// The previous details are used when calculating line items so keep it before any code that 'does something'
if (!empty($contribution->id)) {
$input['prevContribution'] = CRM_Contribute_BAO_Contribution::getValues(['id' => $contribution->id]);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public static function sendMail($contactID, $values, $isTest = FALSE, $returnMes
);
}

$title = isset($values['title']) ? $values['title'] : CRM_Contribute_BAO_Contribution_Utils::getContributionPageTitle($values['contribution_page_id']);
$title = $values['title'] ?? CRM_Contribute_BAO_Contribution_Utils::getContributionPageTitle($values['contribution_page_id']);

// Set email variables explicitly to avoid leaky smarty variables.
// All of these will be assigned to the template, replacing any that might be assigned elsewhere.
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/ContributionSoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public static function getSoftContributionTotals($contact_id, $isTest = 0) {
*/
public static function getSoftContribution($contributionID, $all = FALSE) {
$softContributionFields = self::getSoftCreditContributionFields([$contributionID], $all);
return isset($softContributionFields[$contributionID]) ? $softContributionFields[$contributionID] : [];
return $softContributionFields[$contributionID] ?? [];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function setDefaultValues() {
// For Premium section.
if ($this->_premiumID) {
$this->assign('showOption', FALSE);
$options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : "";
$options = $this->_options[$this->_productDAO->product_id] ?? "";
if (!$options) {
$this->assign('showOption', TRUE);
}
Expand Down Expand Up @@ -430,7 +430,7 @@ public function setDefaultValues() {
$defaults['refund_trxn_id'] = CRM_Core_BAO_FinancialTrxn::getRefundTransactionTrxnID($this->_id);
}
else {
$defaults['refund_trxn_id'] = isset($defaults['trxn_id']) ? $defaults['trxn_id'] : NULL;
$defaults['refund_trxn_id'] = $defaults['trxn_id'] ?? NULL;
}

if (!$this->_id && empty($defaults['receive_date'])) {
Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ protected function postProcessMembership(
}
$i++;
$numTerms = CRM_Utils_Array::value($memType, $typesTerms, 1);
$contributionRecurID = isset($form->_params['contributionRecurID']) ? $form->_params['contributionRecurID'] : NULL;
$contributionRecurID = $form->_params['contributionRecurID'] ?? NULL;

$membershipSource = NULL;
if (!empty($form->_params['membership_source'])) {
Expand Down Expand Up @@ -1945,7 +1945,7 @@ public static function submit($params) {
$capabilities[] = (ucfirst($form->_mode) . 'Mode');
}
$form->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors($capabilities);
$form->_params['payment_processor_id'] = isset($params['payment_processor_id']) ? $params['payment_processor_id'] : 0;
$form->_params['payment_processor_id'] = $params['payment_processor_id'] ?? 0;
if ($form->_params['payment_processor_id'] !== '') {
// It can be blank with a $0 transaction - then no processor needs to be selected
$form->_paymentProcessor = $form->_paymentProcessors[$form->_params['payment_processor_id']];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
* @return bool
*/
public function isQuickConfig() {
return isset(self::$_quickConfig) ? self::$_quickConfig : FALSE;
return self::$_quickConfig ?? FALSE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function getSubscriptionDetails() {
*/
protected function getSubscriptionContactID() {
$sub = $this->getSubscriptionDetails();
return isset($sub->contact_id) ? $sub->contact_id : FALSE;
return $sub->contact_id ?? FALSE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Task/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function postProcess() {
$input['fee_amount'] = $contribution->fee_amount;
$input['net_amount'] = $contribution->net_amount;
$input['trxn_id'] = $contribution->trxn_id;
$input['trxn_date'] = isset($contribution->trxn_date) ? $contribution->trxn_date : NULL;
$input['trxn_date'] = $contribution->trxn_date ?? NULL;
$input['receipt_update'] = $params['receipt_update'];
$input['contribution_status_id'] = $contribution->contribution_status_id;
$input['paymentProcessor'] = empty($contribution->trxn_id) ? NULL :
Expand Down
8 changes: 4 additions & 4 deletions CRM/Contribute/Form/Task/PDFLetterCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public static function postProcess(&$form, $formValues = NULL) {
}
}
// update dates ?
$receipt_update = isset($formValues['receipt_update']) ? $formValues['receipt_update'] : FALSE;
$thankyou_update = isset($formValues['thankyou_update']) ? $formValues['thankyou_update'] : FALSE;
$receipt_update = $formValues['receipt_update'] ?? FALSE;
$thankyou_update = $formValues['thankyou_update'] ?? FALSE;
$nowDate = date('YmdHis');
$receipts = $thanks = $emailed = 0;
$updateStatus = '';
Expand All @@ -75,8 +75,8 @@ public static function postProcess(&$form, $formValues = NULL) {
$groupBy = $formValues['group_by'];

// skip some contacts ?
$skipOnHold = isset($form->skipOnHold) ? $form->skipOnHold : FALSE;
$skipDeceased = isset($form->skipDeceased) ? $form->skipDeceased : TRUE;
$skipOnHold = $form->skipOnHold ?? FALSE;
$skipDeceased = $form->skipDeceased ?? TRUE;
$contributionIDs = $form->getVar('_contributionIds');
if ($form->_includesSoftCredits) {
//@todo - comment on what is stored there
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/UpdateSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function setDefaultValues() {
$this->_defaults['financial_type_id'] = $this->_subscriptionDetails->financial_type_id;
$this->_defaults['is_notify'] = 1;
foreach ($this->editableScheduleFields as $field) {
$this->_defaults[$field] = isset($this->_subscriptionDetails->$field) ? $this->_subscriptionDetails->$field : NULL;
$this->_defaults[$field] = $this->_subscriptionDetails->$field ?? NULL;
}

return $this->_defaults;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function preProcess() {
$this->assign('dataValues', $this->_dataValues);

$skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
$this->_onDuplicate = $this->get('onDuplicate', isset($onDuplicate) ? $onDuplicate : "");
$this->_onDuplicate = $this->get('onDuplicate', $onDuplicate ?? "");

if ($skipColumnHeader) {
$this->assign('skipColumnHeader', $skipColumnHeader);
Expand Down