From a5fb978c919872a8cb933d5e105e3b385931863f Mon Sep 17 00:00:00 2001 From: colemanw Date: Mon, 3 Jul 2023 14:34:29 -0400 Subject: [PATCH] Code cleanup; remove unused vars and remove CRM_Utils_Array::value --- CRM/Core/BAO/CustomField.php | 21 +++++++++------------ CRM/Core/BAO/CustomQuery.php | 6 ++---- CRM/Utils/Address.php | 22 +++++++--------------- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 75cd9ca436..7eec0c77a3 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -443,9 +443,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $cacheKey = md5($cacheKey); } - if (!self::$_importFields || - CRM_Utils_Array::value($cacheKey, self::$_importFields) === NULL - ) { + if (!isset(self::$_importFields[$cacheKey])) { if (!self::$_importFields) { self::$_importFields = []; } @@ -570,7 +568,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $fields[$dao->id]['groupTitle'] = $dao->title; $fields[$dao->id]['data_type'] = $dao->data_type; $fields[$dao->id]['name'] = 'custom_' . $dao->id; - $fields[$dao->id]['type'] = CRM_Utils_Array::value($dao->data_type, self::dataToType()); + $fields[$dao->id]['type'] = self::dataToType()[$dao->data_type] ?? NULL; $fields[$dao->id]['html_type'] = $dao->html_type; $fields[$dao->id]['default_value'] = $dao->default_value; $fields[$dao->id]['text_length'] = $dao->text_length; @@ -760,8 +758,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { * * @param bool $all * - * @return int|null - * The id (if exists) + * @return array|int|null */ public static function getKeyID($key, $all = FALSE) { $match = []; @@ -772,7 +769,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { else { return [ $match[1], - CRM_Utils_Array::value(2, $match), + $match[2] ?? NULL, ]; } } @@ -1265,7 +1262,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { $display = implode(', ', $v); } else { - $display = CRM_Utils_Array::value($value, $field['options'], ''); + $display = $field['options'][$value] ?? ''; // For float type (see Number and Money) $value would be decimal like // 1.00 (because it is stored in db as decimal), while options array // key would be integer like 1. In this case expression on line above @@ -1296,7 +1293,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { if ($format) { if (array_key_exists($format, $actualPHPFormats)) { $customTimeFormat = (array) $actualPHPFormats[$format]; - switch (CRM_Utils_Array::value('time_format', $field)) { + switch ($field['time_format'] ?? NULL) { case 1: $customTimeFormat[] = 'g:iA'; break; @@ -2119,7 +2116,7 @@ WHERE id IN ( %1, %2 ) */ protected static function prepareCreate($params) { $op = empty($params['id']) ? 'create' : 'edit'; - CRM_Utils_Hook::pre($op, 'CustomField', CRM_Utils_Array::value('id', $params), $params); + CRM_Utils_Hook::pre($op, 'CustomField', $params['id'] ?? NULL, $params); $params['is_append_field_id_to_column_name'] = !isset($params['column_name']); if ($op === 'create') { CRM_Core_DAO::setCreateDefaults($params, self::getDefaults()); @@ -2675,7 +2672,7 @@ WHERE f.id IN ($ids)"; } $dataType = $field->data_type; - $profileField = CRM_Utils_Array::value($key, $profileFields, []); + $profileField = $profileFields[$key] ?? []; $fieldTitle = $profileField['title'] ?? NULL; $isRequired = $profileField['is_required'] ?? NULL; if (!$fieldTitle) { @@ -2687,7 +2684,7 @@ WHERE f.id IN ($ids)"; continue; } - //lets validate first for required field. + // Validate first for required field. if ($isRequired && CRM_Utils_System::isNull($value)) { $errors[$key] = ts('%1 is a required field.', [1 => $fieldTitle]); continue; diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index 002f5fba26..7948b7eaf0 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -177,9 +177,7 @@ class CRM_Core_BAO_CustomQuery { foreach ($this->_ids as $id => $values) { // Fixed for Issue CRM 607 - if (CRM_Utils_Array::value($id, $this->_fields) === NULL || - !$values - ) { + if (!isset($this->_fields[$id]) || !$values) { continue; } @@ -207,7 +205,7 @@ class CRM_Core_BAO_CustomQuery { $qillValue = CRM_Core_BAO_CustomField::displayValue($value, $id); } - $qillOp = CRM_Utils_Array::value($op, CRM_Core_SelectValues::getSearchBuilderOperators(), $op); + $qillOp = CRM_Core_SelectValues::getSearchBuilderOperators()[$op] ?? $op; // Ensure the table is joined in (eg if in where but not select). $this->joinCustomTableForField($field); diff --git a/CRM/Utils/Address.php b/CRM/Utils/Address.php index 5436f0534d..62c5b2a88f 100644 --- a/CRM/Utils/Address.php +++ b/CRM/Utils/Address.php @@ -47,7 +47,6 @@ class CRM_Utils_Address { $mailing = FALSE, $tokenFields = NULL ) { - static $config = NULL; $mailing = FALSE; if (!$format) { @@ -167,12 +166,10 @@ class CRM_Utils_Address { 'contact.world_region' => "" . $fields['world_region'] . "", ]; - // erase all empty ones, so we dont get blank lines + // Erase all empty ones, so we don't get blank lines foreach (array_keys($replacements) as $key) { $exactKey = substr($key, 0, 8) == 'contact.' ? substr($key, 8) : $key; - if ($key != 'contact.postal_code' && - CRM_Utils_Array::value($exactKey, $fields) == NULL - ) { + if ($key !== 'contact.postal_code' && empty($fields[$exactKey])) { $replacements[$key] = ''; } } @@ -244,7 +241,6 @@ class CRM_Utils_Address { else { // remove \n from each line and only add at the end // this hack solves formatting issue, when we convert nl2br - $lines = []; $count = 1; $finalFormatted = NULL; $formattedArray = explode("\n", $formatted); @@ -276,12 +272,12 @@ class CRM_Utils_Address { * * @param array $fields * The address fields. - * @param string $format - * The desired address format. + * @param null $format + * Unused var. * @param bool $microformat - * If true indicates, the address to be built in hcard-microformat standard. + * Unused var. * @param bool $mailing - * If true indicates, the call has been made from mailing label. + * Unused var. * @param null $tokenFields * * @return string @@ -295,11 +291,7 @@ class CRM_Utils_Address { $mailing = FALSE, $tokenFields = NULL ) { - static $config = NULL; - - $format = Civi::settings()->get('mailing_format'); - - $formatted = $format; + $formatted = Civi::settings()->get('mailing_format'); $fullPostalCode = $fields['postal_code'] ?? NULL; if (!empty($fields['postal_code_suffix'])) { -- 2.25.1