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] Cleanup uses of CRM_Utils_Array::value related to numbers #16778

Merged
merged 1 commit into from
Mar 16, 2020

Conversation

colemanw
Copy link
Member

Overview

Some manual cleanup around the areas of code where CRM_Utils_Array::value is used for a number defaulting to 0. Fixes test failures in #16768.

Before

Messier code.

After

Neater code.

Technical Details

This was manual cleanup, not regex find/replace. The expressions are not always identical before/after, but should work the same in their particular contexts of possible inputs and expected outputs.

@civibot
Copy link

civibot bot commented Mar 15, 2020

(Standard links)

@civibot civibot bot added the master label Mar 15, 2020
@@ -341,7 +341,7 @@ public static function recipientListing() {
* Used by jstree to incrementally load tags
*/
public static function getTagTree() {
$parent = CRM_Utils_Type::escape(CRM_Utils_Array::value('parent_id', $_GET, 0), 'Integer');
$parent = CRM_Utils_Type::escape(($_GET['parent_id'] ?? 0), 'Integer');
Copy link
Member Author

Choose a reason for hiding this comment

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

Before/after should work the same given that it's being passed into CRM_Utils_Type::escape()

@@ -373,7 +373,6 @@ public static function buildAdminLinks(&$menu) {
$values[$item['adminGroup']] = array();
$values[$item['adminGroup']]['fields'] = array();
}
$weight = CRM_Utils_Array::value('weight', $item, 0);
Copy link
Member Author

Choose a reason for hiding this comment

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

This variable was unused.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

$params['name'],
CRM_Utils_Array::value('addSequence', $params, 0)
);
return CRM_Core_Key::get($params['name'], $params['addSequence'] ?? FALSE);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is better because CRM_Core_Key::get() expects a boolean not an int.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree

$is_count = $params['options']['is_count'] ?? FALSE;
$offset = $params['options']['offset'] ?? $offset;
$limit = CRM_Utils_Array::value('limit', $params['options'], $limit);
$sort = $params['options']['sort'] ?? $sort;
Copy link
Member Author

Choose a reason for hiding this comment

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

I left $limit alone here b/c there are more edge cases around a non-falsey default of 25. But defaulting to 0 is pretty simple with coalesce.

elseif (in_array($n, $otherVars)) {
}
else {
elseif (!in_array($n, $otherVars)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This was silly.

Some manual cleanup around the areas of code where CRM_Utils_Array::value is used for a number defaulting to 0
@@ -73,7 +73,7 @@ function _civicrm_api3_dashboard_contact_create_spec(&$params) {
function _civicrm_api3_dashboard_contact_check_params(&$params) {
$dashboard_id = CRM_Utils_Array::value('dashboard_id', $params);
if ($dashboard_id) {
$allDashlets = CRM_Core_BAO_Dashboard::getDashlets(TRUE, CRM_Utils_Array::value('check_permissions', $params, 0));
$allDashlets = CRM_Core_BAO_Dashboard::getDashlets(TRUE, $params['check_permissions'] ?? FALSE);
Copy link
Member Author

Choose a reason for hiding this comment

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

Better because CRM_Core_BAO_Dashboard::getDashlets() expects a boolean not an int.

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed

@eileenmcnaughton
Copy link
Contributor

OK - I managed to work through these & they all make sense - merging

@eileenmcnaughton eileenmcnaughton merged commit adec7a2 into civicrm:master Mar 16, 2020
@eileenmcnaughton eileenmcnaughton deleted the arrayValue6 branch March 16, 2020 00:05
@colemanw
Copy link
Member Author

Thanks @eileenmcnaughton!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants