-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
Conversation
(Standard links)
|
@@ -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'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable was unused.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
OK - I managed to work through these & they all make sense - merging |
Thanks @eileenmcnaughton! |
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.