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 810cec0d4a09..9277e4f04014 100644 --- a/CRM/Campaign/BAO/Survey.php +++ b/CRM/Campaign/BAO/Survey.php @@ -886,7 +886,7 @@ public static function getSurveyProfileId($surveyId) { } } - 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 469888439601..f068d0a0337c 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -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; diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 3f2ca58df0f7..9ec355bb6ecd 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -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; } /** diff --git a/CRM/Core/Component.php b/CRM/Core/Component.php index 73cb707a5ad1..10b302d5f5f8 100644 --- a/CRM/Core/Component.php +++ b/CRM/Core/Component.php @@ -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; } diff --git a/CRM/Core/Controller.php b/CRM/Core/Controller.php index 6f2ea70368ae..8cdb5a2d5226 100644 --- a/CRM/Core/Controller.php +++ b/CRM/Core/Controller.php @@ -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; } /** diff --git a/CRM/Core/Payment/Form.php b/CRM/Core/Payment/Form.php index 1881d38554e4..496f46d22ee1 100644 --- a/CRM/Core/Payment/Form.php +++ b/CRM/Core/Payment/Form.php @@ -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; } /** @@ -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; } /** diff --git a/CRM/Core/Payment/PayPalProIPN.php b/CRM/Core/Payment/PayPalProIPN.php index 42c23e308799..359937e6cb2a 100644 --- a/CRM/Core/Payment/PayPalProIPN.php +++ b/CRM/Core/Payment/PayPalProIPN.php @@ -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; } } diff --git a/CRM/Core/PseudoConstant.php b/CRM/Core/PseudoConstant.php index 2c9dee0a09e1..1e3f80bd4959 100644 --- a/CRM/Core/PseudoConstant.php +++ b/CRM/Core/PseudoConstant.php @@ -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; } /** @@ -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; } /** @@ -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]; diff --git a/CRM/Core/Session.php b/CRM/Core/Session.php index 8cbcfdfeada0..037efb1115b5 100644 --- a/CRM/Core/Session.php +++ b/CRM/Core/Session.php @@ -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; } /** diff --git a/CRM/Event/Cart/BAO/Cart.php b/CRM/Event/Cart/BAO/Cart.php index ac4090363f61..1acabfe0a3bd 100644 --- a/CRM/Event/Cart/BAO/Cart.php +++ b/CRM/Event/Cart/BAO/Cart.php @@ -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; } /** diff --git a/CRM/Event/PseudoConstant.php b/CRM/Event/PseudoConstant.php index 9fd6a842ff6a..780adc60b115 100644 --- a/CRM/Event/PseudoConstant.php +++ b/CRM/Event/PseudoConstant.php @@ -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; } return self::$pcPage; } diff --git a/CRM/Financial/Form/SalesTaxTrait.php b/CRM/Financial/Form/SalesTaxTrait.php index 777895dbb091..888ac75f9760 100644 --- a/CRM/Financial/Form/SalesTaxTrait.php +++ b/CRM/Financial/Form/SalesTaxTrait.php @@ -41,7 +41,7 @@ public function getSalesTaxTerm() { 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 daf3088747e8..dbcc4befacd8 100644 --- a/CRM/Invoicing/Utils.php +++ b/CRM/Invoicing/Utils.php @@ -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; } /** @@ -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; } } diff --git a/CRM/Logging/ReportSummary.php b/CRM/Logging/ReportSummary.php index 2a882e842d8e..364474b199da 100644 --- a/CRM/Logging/ReportSummary.php +++ b/CRM/Logging/ReportSummary.php @@ -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; } } } diff --git a/CRM/Report/Form/Contact/Relationship.php b/CRM/Report/Form/Contact/Relationship.php index f2756c3e65a3..4807844732a6 100644 --- a/CRM/Report/Form/Contact/Relationship.php +++ b/CRM/Report/Form/Contact/Relationship.php @@ -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; } /** diff --git a/CRM/Report/Utils/Report.php b/CRM/Report/Utils/Report.php index 276ef7fe6bca..329bf0f83575 100644 --- a/CRM/Report/Utils/Report.php +++ b/CRM/Report/Utils/Report.php @@ -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; } /** diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 29b043f1568e..9f71dab6d638 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -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; } /** diff --git a/tests/phpunit/api/v3/TaxContributionPageTest.php b/tests/phpunit/api/v3/TaxContributionPageTest.php index 0bbc33074928..3c2b82e73f7c 100644 --- a/tests/phpunit/api/v3/TaxContributionPageTest.php +++ b/tests/phpunit/api/v3/TaxContributionPageTest.php @@ -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; } /**