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] Use ?? operator instead of CRM_Utils_Array::value() in return statements #16719

Merged
merged 1 commit into from
Mar 10, 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/Campaign/BAO/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ public static function getSurveyProfileId($surveyId) {
}
}

return CRM_Utils_Array::value($surveyId, $ufIds);
return $ufIds[$surveyId] ?? NULL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -3620,7 +3620,7 @@ public static function getFirstDuplicateContact($input, $contactType, $rule = 'U
public static function isFieldHasLocationType($fieldTitle) {
foreach (CRM_Contact_BAO_Contact::importableFields() as $key => $field) {
if ($field['title'] === $fieldTitle) {
return CRM_Utils_Array::value('hasLocationType', $field);
return $field['hasLocationType'] ?? NULL;
}
}
return FALSE;
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 @@ -5008,7 +5008,7 @@ protected function addContributionPageValuesToValuesHeavyHandedly(&$values) {
*/
public static function checkContributeSettings($name) {
$contributeSettings = Civi::settings()->get('contribution_invoice_settings');
return CRM_Utils_Array::value($name, $contributeSettings);
return $contributeSettings[$name] ?? NULL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static function &_info($force = FALSE) {
public static function get($name, $attribute = NULL) {
$comp = CRM_Utils_Array::value($name, self::_info());
if ($attribute) {
return CRM_Utils_Array::value($attribute, $comp->info);
return $comp->info[$attribute] ?? NULL;
}
return $comp;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public function addPages(&$stateMachine, $action = CRM_Core_Action::NONE) {
*/
public function getButtonName() {
$data = &$this->container();
return CRM_Utils_Array::value('_qf_button_name', $data);
return $data['_qf_button_name'] ?? NULL;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Payment/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public static function getCreditCardExpirationMonth($src) {
return $month;
}

return CRM_Utils_Array::value('m', $src['credit_card_exp_date']);
return $src['credit_card_exp_date']['m'] ?? NULL;
}

/**
Expand All @@ -388,7 +388,7 @@ public static function getCreditCardExpirationMonth($src) {
* @return int
*/
public static function getCreditCardExpirationYear($src) {
return CRM_Utils_Array::value('Y', $src['credit_card_exp_date']);
return $src['credit_card_exp_date']['Y'] ?? NULL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getValue($name, $abort = TRUE) {
throw new CRM_Core_Exception("Failure: Missing Parameter $name");
}
else {
return CRM_Utils_Array::value($name, $this->_invoiceData);
return $this->_invoiceData[$name] ?? NULL;
}
}

Expand Down
6 changes: 3 additions & 3 deletions CRM/Core/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public static function getLabel($baoName, $fieldName, $key) {
if ($values === FALSE) {
return FALSE;
}
return CRM_Utils_Array::value($key, $values);
return $values[$key] ?? NULL;
}

/**
Expand All @@ -417,7 +417,7 @@ public static function getName($baoName, $fieldName, $key) {
if ($values === FALSE) {
return FALSE;
}
return CRM_Utils_Array::value($key, $values);
return $values[$key] ?? NULL;
}

/**
Expand Down Expand Up @@ -1478,7 +1478,7 @@ public static function accountOptionValues($optionGroupName, $id = NULL, $condit
self::$accountOptionValues[$cacheKey] = CRM_Core_OptionGroup::values($optionGroupName, FALSE, FALSE, FALSE, $condition);
}
if ($id) {
return CRM_Utils_Array::value($id, self::$accountOptionValues[$cacheKey]);
return self::$accountOptionValues[$cacheKey][$id] ?? NULL;
}

return self::$accountOptionValues[$cacheKey];
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function get($name, $prefix = NULL) {
$session =& $this->_session[$this->_key][$prefix];
}

return CRM_Utils_Array::value($name, $session);
return $session[$name] ?? NULL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Cart/BAO/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function get_subparticipants($main_participant) {
* @return mixed
*/
public function get_event_in_cart_by_event_id($event_id) {
return CRM_Utils_Array::value($event_id, $this->events_in_carts);
return $this->events_in_carts[$event_id] ?? NULL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public static function &pcPage($id = NULL) {
);
}
if ($id) {
return CRM_Utils_Array::value($id, self::$pcPage);
return self::$pcPage[$id] ?? NULL;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@twomice this is the only return-by-ref function affected by this PR. I'll do a followup to remove the & from the function declaration per your comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out the function was unused. #16771

}
return self::$pcPage;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Financial/Form/SalesTaxTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getSalesTaxTerm() {
if (!$invoicing) {
return '';
}
return CRM_Utils_Array::value('tax_term', $invoiceSettings);
return $invoiceSettings['tax_term'] ?? NULL;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Invoicing/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function isInvoicingEnabled() {
return TRUE;
}
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
return CRM_Utils_Array::value('invoicing', $invoiceSettings);
return $invoiceSettings['invoicing'] ?? NULL;
}

/**
Expand All @@ -70,7 +70,7 @@ public static function isInvoicingEnabled() {
*/
public static function getTaxTerm() {
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
return CRM_Utils_Array::value('tax_term', $invoiceSettings);
return $invoiceSettings['tax_term'] ?? NULL;
}

}
2 changes: 1 addition & 1 deletion CRM/Logging/ReportSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function getEntityValue($id, $entity, $logDate) {
if (array_key_exists('options', $this->_logTables[$entity]['bracket_info']) &&
$entityID
) {
return CRM_Utils_Array::value($entityID, $this->_logTables[$entity]['bracket_info']['options']);
return $this->_logTables[$entity]['bracket_info']['options'][$entityID] ?? NULL;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Form/Contact/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public static function permissionedRelationship($key) {
if (!$lookup) {
$lookup = CRM_Contact_BAO_Relationship::buildOptions("is_permission_a_b");
};
return CRM_Utils_Array::value($key, $lookup);
return $lookup[$key] ?? NULL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Utils/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function getInstanceIDForPath($path = NULL) {
$params = [1 => [$path, 'String']];
$valId[$path] = CRM_Core_DAO::singleValueQuery($sql, $params);
}
return CRM_Utils_Array::value($path, $valId);
return $valId[$path] ?? NULL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Utils/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ public static function ipAddress($strictIPV4 = TRUE) {
* The previous page URL
*/
public static function refererPath() {
return CRM_Utils_Array::value('HTTP_REFERER', $_SERVER);
return $_SERVER['HTTP_REFERER'] ?? NULL;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/TaxContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public function _getFinancialAccountId($financialTypeId) {

$result = [];
CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result);
return CRM_Utils_Array::value('financial_account_id', $result);
return $result['financial_account_id'] ?? NULL;
}

/**
Expand Down