From 914d3734262de491f6a98f84cd5b78c48c7dd365 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 9 Mar 2020 11:50:45 -0400 Subject: [PATCH] Use ?? operator instead of CRM_Utils_Array::value() in return statements --- CRM/Campaign/BAO/Survey.php | 2 +- CRM/Contact/BAO/Contact.php | 2 +- CRM/Contribute/BAO/Contribution.php | 2 +- CRM/Core/Component.php | 2 +- CRM/Core/Controller.php | 2 +- CRM/Core/Payment/Form.php | 4 ++-- CRM/Core/Payment/PayPalProIPN.php | 2 +- CRM/Core/PseudoConstant.php | 6 +++--- CRM/Core/Session.php | 2 +- CRM/Event/Cart/BAO/Cart.php | 2 +- CRM/Event/PseudoConstant.php | 2 +- CRM/Financial/Form/SalesTaxTrait.php | 2 +- CRM/Invoicing/Utils.php | 4 ++-- CRM/Logging/ReportSummary.php | 2 +- CRM/Report/Form/Contact/Relationship.php | 2 +- CRM/Report/Utils/Report.php | 2 +- CRM/Utils/System.php | 2 +- tests/phpunit/api/v3/TaxContributionPageTest.php | 2 +- 18 files changed, 22 insertions(+), 22 deletions(-) diff --git a/CRM/Campaign/BAO/Survey.php b/CRM/Campaign/BAO/Survey.php index 810cec0d4a..9277e4f040 100644 --- a/CRM/Campaign/BAO/Survey.php +++ b/CRM/Campaign/BAO/Survey.php @@ -886,7 +886,7 @@ INNER JOIN civicrm_contact contact_a ON ( activityTarget.contact_id = contact_a } } - return CRM_Utils_Array::value($surveyId, $ufIds); + return $ufIds[$surveyId] ?? NULL; } /** diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 4698884396..f068d0a033 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -3620,7 +3620,7 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id ) 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; diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 3f2ca58df0..9ec355bb6e 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -5008,7 +5008,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac */ public static function checkContributeSettings($name) { $contributeSettings = Civi::settings()->get('contribution_invoice_settings'); - return CRM_Utils_Array::value($name, $contributeSettings); + return $contributeSettings[$name] ?? NULL; } /** diff --git a/CRM/Core/Component.php b/CRM/Core/Component.php index 73cb707a5a..10b302d5f5 100644 --- a/CRM/Core/Component.php +++ b/CRM/Core/Component.php @@ -63,7 +63,7 @@ class CRM_Core_Component { 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; } diff --git a/CRM/Core/Controller.php b/CRM/Core/Controller.php index 6f2ea70368..8cdb5a2d52 100644 --- a/CRM/Core/Controller.php +++ b/CRM/Core/Controller.php @@ -464,7 +464,7 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { */ public function getButtonName() { $data = &$this->container(); - return CRM_Utils_Array::value('_qf_button_name', $data); + return $data['_qf_button_name'] ?? NULL; } /** diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 1881d38554..496f46d22e 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -375,7 +375,7 @@ class CRM_Core_Payment_Form { return $month; } - return CRM_Utils_Array::value('m', $src['credit_card_exp_date']); + return $src['credit_card_exp_date']['m'] ?? NULL; } /** @@ -388,7 +388,7 @@ class CRM_Core_Payment_Form { * @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; } /** diff --git a/CRM/Core/Payment/PayPalProIPN.php b/CRM/Core/Payment/PayPalProIPN.php index 42c23e3087..359937e6cb 100644 --- a/CRM/Core/Payment/PayPalProIPN.php +++ b/CRM/Core/Payment/PayPalProIPN.php @@ -76,7 +76,7 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN { throw new CRM_Core_Exception("Failure: Missing Parameter $name"); } else { - return CRM_Utils_Array::value($name, $this->_invoiceData); + return $this->_invoiceData[$name] ?? NULL; } } diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 2c9dee0a09..1e3f80bd49 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -397,7 +397,7 @@ class CRM_Core_PseudoConstant { if ($values === FALSE) { return FALSE; } - return CRM_Utils_Array::value($key, $values); + return $values[$key] ?? NULL; } /** @@ -417,7 +417,7 @@ class CRM_Core_PseudoConstant { if ($values === FALSE) { return FALSE; } - return CRM_Utils_Array::value($key, $values); + return $values[$key] ?? NULL; } /** @@ -1478,7 +1478,7 @@ WHERE id = %1 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]; diff --git a/CRM/Core/Session.php b/CRM/Core/Session.php index 8cbcfdfead..037efb1115 100644 --- a/CRM/Core/Session.php +++ b/CRM/Core/Session.php @@ -250,7 +250,7 @@ class CRM_Core_Session { $session =& $this->_session[$this->_key][$prefix]; } - return CRM_Utils_Array::value($name, $session); + return $session[$name] ?? NULL; } /** diff --git a/CRM/Event/Cart/BAO/Cart.php b/CRM/Event/Cart/BAO/Cart.php index ac4090363f..1acabfe0a3 100644 --- a/CRM/Event/Cart/BAO/Cart.php +++ b/CRM/Event/Cart/BAO/Cart.php @@ -238,7 +238,7 @@ class CRM_Event_Cart_BAO_Cart extends CRM_Event_Cart_DAO_Cart { * @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; } /** diff --git a/CRM/Event/PseudoConstant.php b/CRM/Event/PseudoConstant.php index 9fd6a842ff..780adc60b1 100644 --- a/CRM/Event/PseudoConstant.php +++ b/CRM/Event/PseudoConstant.php @@ -298,7 +298,7 @@ class CRM_Event_PseudoConstant extends CRM_Core_PseudoConstant { ); } if ($id) { - return CRM_Utils_Array::value($id, self::$pcPage); + return self::$pcPage[$id] ?? NULL; } return self::$pcPage; } diff --git a/CRM/Financial/Form/SalesTaxTrait.php b/CRM/Financial/Form/SalesTaxTrait.php index 777895dbb0..888ac75f97 100644 --- a/CRM/Financial/Form/SalesTaxTrait.php +++ b/CRM/Financial/Form/SalesTaxTrait.php @@ -41,7 +41,7 @@ trait CRM_Financial_Form_SalesTaxTrait { if (!$invoicing) { return ''; } - return CRM_Utils_Array::value('tax_term', $invoiceSettings); + return $invoiceSettings['tax_term'] ?? NULL; } /** diff --git a/CRM/Invoicing/Utils.php b/CRM/Invoicing/Utils.php index daf3088747..dbcc4befac 100644 --- a/CRM/Invoicing/Utils.php +++ b/CRM/Invoicing/Utils.php @@ -59,7 +59,7 @@ class CRM_Invoicing_Utils { return TRUE; } $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); - return CRM_Utils_Array::value('invoicing', $invoiceSettings); + return $invoiceSettings['invoicing'] ?? NULL; } /** @@ -70,7 +70,7 @@ class CRM_Invoicing_Utils { */ public static function getTaxTerm() { $invoiceSettings = Civi::settings()->get('contribution_invoice_settings'); - return CRM_Utils_Array::value('tax_term', $invoiceSettings); + return $invoiceSettings['tax_term'] ?? NULL; } } diff --git a/CRM/Logging/ReportSummary.php b/CRM/Logging/ReportSummary.php index 2a882e842d..364474b199 100644 --- a/CRM/Logging/ReportSummary.php +++ b/CRM/Logging/ReportSummary.php @@ -280,7 +280,7 @@ WHERE log_date <= %1 AND id = %2 ORDER BY log_date DESC LIMIT 1"; 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; } } } diff --git a/CRM/Report/Form/Contact/Relationship.php b/CRM/Report/Form/Contact/Relationship.php index f2756c3e65..4807844732 100644 --- a/CRM/Report/Form/Contact/Relationship.php +++ b/CRM/Report/Form/Contact/Relationship.php @@ -792,7 +792,7 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form { if (!$lookup) { $lookup = CRM_Contact_BAO_Relationship::buildOptions("is_permission_a_b"); }; - return CRM_Utils_Array::value($key, $lookup); + return $lookup[$key] ?? NULL; } /** diff --git a/CRM/Report/Utils/Report.php b/CRM/Report/Utils/Report.php index 276ef7fe6b..329bf0f835 100644 --- a/CRM/Report/Utils/Report.php +++ b/CRM/Report/Utils/Report.php @@ -99,7 +99,7 @@ WHERE TRIM(BOTH '/' FROM CONCAT(report_id, '/', name)) = %1"; $params = [1 => [$path, 'String']]; $valId[$path] = CRM_Core_DAO::singleValueQuery($sql, $params); } - return CRM_Utils_Array::value($path, $valId); + return $valId[$path] ?? NULL; } /** diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 29b043f156..9f71dab6d6 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -1278,7 +1278,7 @@ class CRM_Utils_System { * The previous page URL */ public static function refererPath() { - return CRM_Utils_Array::value('HTTP_REFERER', $_SERVER); + return $_SERVER['HTTP_REFERER'] ?? NULL; } /** diff --git a/tests/phpunit/api/v3/TaxContributionPageTest.php b/tests/phpunit/api/v3/TaxContributionPageTest.php index 0bbc330749..3c2b82e73f 100644 --- a/tests/phpunit/api/v3/TaxContributionPageTest.php +++ b/tests/phpunit/api/v3/TaxContributionPageTest.php @@ -501,7 +501,7 @@ class api_v3_TaxContributionPageTest extends CiviUnitTestCase { $result = []; CRM_Financial_BAO_FinancialTypeAccount::retrieve($searchParams, $result); - return CRM_Utils_Array::value('financial_account_id', $result); + return $result['financial_account_id'] ?? NULL; } /** -- 2.25.1