From e01bf59736738a5e100c8192388ca732524d97f4 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 21 Mar 2020 14:01:14 -0400 Subject: [PATCH] Cleanup is_array(CRM_Utils_Array::value()) pattern --- CRM/Activity/BAO/Activity.php | 2 +- CRM/Contact/BAO/Relationship.php | 9 ++------- CRM/Contact/Import/Parser/Contact.php | 2 +- CRM/Core/BAO/Dashboard.php | 2 +- CRM/Custom/Page/Group.php | 2 +- CRM/Member/BAO/Membership.php | 2 +- CRM/Report/Form/Campaign/SurveyDetails.php | 9 +++------ CRM/Utils/System/DrupalBase.php | 5 +---- api/v3/Generic.php | 2 +- api/v3/Setting.php | 2 +- api/v3/utils.php | 2 +- 11 files changed, 14 insertions(+), 25 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index c2e818108c..b3457a2e3a 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -149,7 +149,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } $transaction = new CRM_Core_Transaction(); - if (is_array(CRM_Utils_Array::value('source_record_id', $params))) { + if (isset($params['source_record_id']) && is_array($params['source_record_id'])) { $sourceRecordIds = implode(',', $params['source_record_id']); } else { diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index 18dd1a5472..53a3454fb9 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -516,16 +516,11 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { * Check if there is data to create the object. * * @param array $params - * (reference ) an assoc array of name/value pairs. * * @return bool */ - public static function dataExists(&$params) { - // return if no data present - if (!is_array(CRM_Utils_Array::value('contact_check', $params))) { - return FALSE; - } - return TRUE; + public static function dataExists($params) { + return (isset($params['contact_check']) && is_array($params['contact_check'])); } /** diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 6cec3b8bb1..bb4be04495 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -1807,7 +1807,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { } foreach ($locationFields as $locKeys) { - if (is_array(CRM_Utils_Array::value($locKeys, $params))) { + if (isset($params[$locKeys]) && is_array($params[$locKeys])) { foreach ($params[$locKeys] as $key => $value) { if ($modeFill) { $getValue = CRM_Utils_Array::retrieveValueRecursive($contact, $locKeys); diff --git a/CRM/Core/BAO/Dashboard.php b/CRM/Core/BAO/Dashboard.php index 575a1a3649..b241a30b10 100644 --- a/CRM/Core/BAO/Dashboard.php +++ b/CRM/Core/BAO/Dashboard.php @@ -423,7 +423,7 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard { $dashlet->id = $dashboardID; } - if (is_array(CRM_Utils_Array::value('permission', $params))) { + if (isset($params['permission']) && is_array($params['permission'])) { $params['permission'] = implode(',', $params['permission']); } $dashlet->copyValues($params); diff --git a/CRM/Custom/Page/Group.php b/CRM/Custom/Page/Group.php index 8fff89132c..d8a931e63d 100644 --- a/CRM/Custom/Page/Group.php +++ b/CRM/Custom/Page/Group.php @@ -303,7 +303,7 @@ class CRM_Custom_Page_Group extends CRM_Core_Page { $customGroup[$key]["extends_entity_column_value"] = $colValue; } else { - if (is_array(CRM_Utils_Array::value($type, $subTypes))) { + if (isset($subTypes[$type]) && is_array($subTypes[$type])) { $customGroup[$key]["extends_entity_column_value"] = ts("Any"); } } diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 226b8e917e..eb2e53c5c2 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1410,7 +1410,7 @@ WHERE civicrm_membership.contact_id = civicrm_contact.id // Reminder should be sent only to the direct membership unset($params['reminder_date']); // unset the custom value ids - if (is_array(CRM_Utils_Array::value('custom', $params))) { + if (isset($params['custom']) && is_array($params['custom'])) { foreach ($params['custom'] as $k => $values) { foreach ($values as $i => $value) { unset($params['custom'][$k][$i]['id']); diff --git a/CRM/Report/Form/Campaign/SurveyDetails.php b/CRM/Report/Form/Campaign/SurveyDetails.php index 97a685973d..5398ef6f5a 100644 --- a/CRM/Report/Form/Campaign/SurveyDetails.php +++ b/CRM/Report/Form/Campaign/SurveyDetails.php @@ -741,14 +741,11 @@ INNER JOIN civicrm_custom_field cf ON ( cg.id = cf.custom_group_id ) if (empty($this->_columns[$resTable]['alias'])) { $this->_columns[$resTable]['alias'] = "{$resTable}_survey_response"; } - if (!is_array(CRM_Utils_Array::value('fields', $this->_columns[$resTable]))) { - $this->_columns[$resTable]['fields'] = array(); + if (empty($this->_columns[$resTable]['fields'])) { + $this->_columns[$resTable]['fields'] = []; } - if (in_array($this->_outputMode, array( - 'print', - 'pdf', - ))) { + if (in_array($this->_outputMode, ['print', 'pdf'])) { $this->_columnTitleOverrides["{$resTable}_{$fieldName}"] = 'Q' . $fieldCnt; $fieldCnt++; } diff --git a/CRM/Utils/System/DrupalBase.php b/CRM/Utils/System/DrupalBase.php index c54fb3db11..a9c72b07db 100644 --- a/CRM/Utils/System/DrupalBase.php +++ b/CRM/Utils/System/DrupalBase.php @@ -659,10 +659,7 @@ abstract class CRM_Utils_System_DrupalBase extends CRM_Utils_System_Base { // Get the menu for above URL. $item = CRM_Core_Menu::get($path); - if (!empty(CRM_Utils_Array::value('is_public', $item))) { - return TRUE; - } - return FALSE; + return !empty($item['is_public']); } /** diff --git a/api/v3/Generic.php b/api/v3/Generic.php index fe355becf2..d8f2e92db4 100644 --- a/api/v3/Generic.php +++ b/api/v3/Generic.php @@ -513,7 +513,7 @@ function _civicrm_api3_generic_get_metadata_options(&$metadata, $apiRequest, $fi } $options = civicrm_api($apiRequest['entity'], 'getoptions', ['version' => 3, 'field' => $fieldname, 'context' => $context]); - if (is_array(CRM_Utils_Array::value('values', $options))) { + if (isset($options['values']) && is_array($options['values'])) { $metadata[$fieldname]['options'] = $options['values']; } } diff --git a/api/v3/Setting.php b/api/v3/Setting.php index 9d8fce5e6c..2f6e7ee6d8 100644 --- a/api/v3/Setting.php +++ b/api/v3/Setting.php @@ -135,7 +135,7 @@ function civicrm_api3_setting_getoptions($params) { $domainId = $params['domain_id'] ?? NULL; $specs = \Civi\Core\SettingsMetadata::getMetadata(['name' => $params['field']], $domainId, TRUE); - if (empty($specs[$params['field']]) || !is_array(CRM_Utils_Array::value('options', $specs[$params['field']]))) { + if (!isset($specs[$params['field']]['options']) || !is_array($specs[$params['field']]['options'])) { throw new API_Exception("The field '" . $params['field'] . "' has no associated option list."); } diff --git a/api/v3/utils.php b/api/v3/utils.php index 3c9ded7475..ded974a55e 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -183,7 +183,7 @@ function civicrm_api3_create_success($values = 1, $params = [], $entity = NULL, } $allFields = []; - if ($action !== 'getfields' && is_array($apiFields) && is_array(CRM_Utils_Array::value('values', $apiFields))) { + if ($action !== 'getfields' && isset($apiFields['values']) && is_array($apiFields['values'])) { $allFields = array_keys($apiFields['values']); } $paramFields = array_keys($params); -- 2.25.1