From f21e34df87e977b3074954655900e0d66da54e56 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 14 Jul 2022 10:38:14 +1000 Subject: [PATCH] [REF][PHP8.1] A third batch of fixes where passing in NULL values causes deprecation notices in php8.1 --- CRM/Case/XMLProcessor/Report.php | 2 +- CRM/Contact/BAO/GroupContact.php | 2 +- CRM/Contact/BAO/Relationship.php | 2 +- CRM/Contact/Form/Task/PDFTrait.php | 2 +- CRM/Core/BAO/Address.php | 2 +- CRM/Core/BAO/CustomField.php | 2 +- CRM/Core/BAO/File.php | 2 +- CRM/Core/Controller.php | 2 +- CRM/Core/Form/Renderer.php | 2 +- CRM/Core/Resources.php | 2 +- CRM/Custom/Form/CustomData.php | 2 +- CRM/Mailing/BAO/Mailing.php | 2 +- CRM/Report/Form.php | 2 +- CRM/Utils/Date.php | 14 +++++++------- CRM/Utils/File.php | 2 +- CRM/Utils/String.php | 8 ++++---- CRM/Utils/System.php | 4 ++-- api/v3/utils.php | 2 +- 18 files changed, 28 insertions(+), 28 deletions(-) diff --git a/CRM/Case/XMLProcessor/Report.php b/CRM/Case/XMLProcessor/Report.php index a0cd56a33f..3eed985011 100644 --- a/CRM/Case/XMLProcessor/Report.php +++ b/CRM/Case/XMLProcessor/Report.php @@ -367,7 +367,7 @@ WHERE a.id = %1 // Is anything depending on this currently or is it just a result of // the see-sawing and some double-escaping that went back and forth // for a few years? - 'value' => htmlspecialchars($this->redact($activityDAO->subject)), + 'value' => htmlspecialchars($this->redact($activityDAO->subject) ?? ''), 'type' => 'Memo', ); diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index dcbafcdfe9..ddae644d62 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -691,7 +691,7 @@ AND contact_id IN ( $contactStr ) $presentIDs = []; $dao = CRM_Core_DAO::executeQuery($sql, $params); if ($dao->fetch()) { - $presentIDs = explode(',', $dao->contactStr); + $presentIDs = explode(',', ($dao->contactStr ?? '')); $presentIDs = array_flip($presentIDs); } diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index cf4281b6ab..46e1794613 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -241,7 +241,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { } CRM_Utils_Hook::pre($hook, 'Relationship', $params['id'], $params); - $relationshipTypes = $params['relationship_type_id'] ?? NULL; + $relationshipTypes = $params['relationship_type_id'] ?? ''; // explode the string with _ to get the relationship type id // and to know which contact has to be inserted in // contact_id_a and which one in contact_id_b diff --git a/CRM/Contact/Form/Task/PDFTrait.php b/CRM/Contact/Form/Task/PDFTrait.php index 61e4faad36..36734bcd8c 100644 --- a/CRM/Contact/Form/Task/PDFTrait.php +++ b/CRM/Contact/Form/Task/PDFTrait.php @@ -505,7 +505,7 @@ trait CRM_Contact_Form_Task_PDFTrait { ], ]; - $htmlMsg = preg_split($newLineOperators['p']['pattern'], $message); + $htmlMsg = preg_split($newLineOperators['p']['pattern'], ($message ?? '')); foreach ($htmlMsg as $k => & $m) { $messages = preg_split($newLineOperators['br']['pattern'], $m); foreach ($messages as $key => & $msg) { diff --git a/CRM/Core/BAO/Address.php b/CRM/Core/BAO/Address.php index 448b2ed3cc..29f94c2a2c 100644 --- a/CRM/Core/BAO/Address.php +++ b/CRM/Core/BAO/Address.php @@ -479,7 +479,7 @@ class CRM_Core_BAO_Address extends CRM_Core_DAO_Address { // added this for CRM 1200 'address_id' => $this->id, // CRM-4003 - 'address_name' => str_replace('', ' ', $this->name), + 'address_name' => str_replace('', ' ', ($this->name ?? '')), 'street_address' => $this->street_address, 'supplemental_address_1' => $this->supplemental_address_1, 'supplemental_address_2' => $this->supplemental_address_2, diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index bfde273fb1..c4c76edcd2 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -764,7 +764,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { // DAO stores attributes as a string, but it's hard to manipulate and // CRM_Core_Form::add() wants them as an array. - $fieldAttributes = self::attributesFromString($field->attributes); + $fieldAttributes = self::attributesFromString($field->attributes ?? ''); // Custom field HTML should indicate group+field name $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id); diff --git a/CRM/Core/BAO/File.php b/CRM/Core/BAO/File.php index 150c3b6e31..a69700fecc 100644 --- a/CRM/Core/BAO/File.php +++ b/CRM/Core/BAO/File.php @@ -338,7 +338,7 @@ class CRM_Core_BAO_File extends CRM_Core_DAO_File { $result['url'] = CRM_Utils_System::url('civicrm/file', "reset=1&id={$dao->cfID}&eid={$dao->entity_id}&fcs={$fileHash}"); $result['href'] = "{$result['cleanName']}"; $result['tag'] = CRM_Core_BAO_EntityTag::getTag($dao->cfID, 'civicrm_file'); - $result['icon'] = CRM_Utils_File::getIconFromMimeType($dao->mime_type); + $result['icon'] = CRM_Utils_File::getIconFromMimeType($dao->mime_type ?? ''); if ($addDeleteArgs) { $result['deleteURLArgs'] = self::deleteURLArgs($dao->entity_table, $dao->entity_id, $dao->cfID); } diff --git a/CRM/Core/Controller.php b/CRM/Core/Controller.php index f31e5f963f..0d642d99f6 100644 --- a/CRM/Core/Controller.php +++ b/CRM/Core/Controller.php @@ -484,7 +484,7 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { */ public function getButtonName() { $data = &$this->container(); - return $data['_qf_button_name'] ?? NULL; + return $data['_qf_button_name'] ?? ''; } /** diff --git a/CRM/Core/Form/Renderer.php b/CRM/Core/Form/Renderer.php index c959a235cd..386c7e9130 100644 --- a/CRM/Core/Form/Renderer.php +++ b/CRM/Core/Form/Renderer.php @@ -222,7 +222,7 @@ class CRM_Core_Form_Renderer extends HTML_QuickForm_Renderer_ArraySmarty { // Temporarily convert string values to an array if (!is_array($val)) { // Try to auto-detect method of serialization - $val = strpos($val, ',') ? explode(',', str_replace(', ', ',', $val)) : (array) CRM_Utils_Array::explodePadded($val); + $val = strpos(($val ?? ''), ',') ? explode(',', str_replace(', ', ',', ($val ?? ''))) : (array) CRM_Utils_Array::explodePadded($val); } if ($val) { $entity = $field->getAttribute('data-api-entity'); diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index f485d6bc56..cc47859bc5 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -449,7 +449,7 @@ class CRM_Core_Resources implements CRM_Core_Resources_CollectionAdderInterface ) { return TRUE; } - list($arg0, $arg1) = array_pad(explode('/', CRM_Utils_System::currentPath()), 2, ''); + list($arg0, $arg1) = array_pad(explode('/', (CRM_Utils_System::currentPath() ?? '')), 2, ''); return ($arg0 === 'civicrm' && in_array($arg1, ['ajax', 'angularprofiles', 'asset'])); } diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index 8d2803cce8..79c9d68c60 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -143,7 +143,7 @@ class CRM_Custom_Form_CustomData { $getCachedTree = $form->_getCachedTree ?? TRUE; $subType = $form->_subType; - if (!is_array($subType) && strstr($subType, CRM_Core_DAO::VALUE_SEPARATOR)) { + if (!is_array($subType) && strstr(($subType ?? ''), CRM_Core_DAO::VALUE_SEPARATOR)) { $subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR)); } diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index d8fe328a9d..f75c0401cb 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -666,7 +666,7 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing { } // To check for an html part strip tags - if (trim(strip_tags($this->body_html, ''))) { + if (trim(strip_tags(($this->body_html ?? ''), ''))) { $template = []; if ($this->header) { diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 35eee9eb3d..49a4d1ace2 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -2287,7 +2287,7 @@ class CRM_Report_Form extends CRM_Core_Form { $sqlOP = $this->getSQLOperator($relative); return "( {$fieldName} {$sqlOP} )"; } - if (strlen($to) === 10) { + if (strlen($to ?? '') === 10) { // If we just have the date we assume the end of that day. $to .= ' 23:59:59'; } diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index f38274517d..48fb0c7c48 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -337,13 +337,13 @@ class CRM_Utils_Date { } } else { - if (strpos($dateString, '-')) { + if (strpos(($dateString ?? ''), '-')) { $month = (int) substr($dateString, 5, 2); $day = (int) substr($dateString, 8, 2); } else { - $month = (int) substr($dateString, 4, 2); - $day = (int) substr($dateString, 6, 2); + $month = (int) substr(($dateString ?? ''), 4, 2); + $day = (int) substr(($dateString ?? ''), 6, 2); } if (strlen($dateString) > 10) { @@ -525,7 +525,7 @@ class CRM_Utils_Date { */ public static function isoToMysql($iso) { $dropArray = ['-' => '', ':' => '', ' ' => '']; - return strtr($iso, $dropArray); + return strtr(($iso ?? ''), $dropArray); } /** @@ -543,7 +543,7 @@ class CRM_Utils_Date { public static function convertToDefaultDate(&$params, $dateType, $dateParam) { $now = getdate(); - $value = NULL; + $value = ''; if (!empty($params[$dateParam])) { // suppress hh:mm or hh:mm:ss if it exists CRM-7957 $value = preg_replace("/(\s(([01]\d)|[2][0-3])(:([0-5]\d)){1,2})$/", "", $params[$dateParam]); @@ -876,8 +876,8 @@ class CRM_Utils_Date { if ($relative) { list($term, $unit) = explode('.', $relative, 2); $dateRange = self::relativeToAbsolute($term, $unit); - $from = substr($dateRange['from'], 0, 8); - $to = substr($dateRange['to'], 0, 8); + $from = substr(($dateRange['from'] ?? ''), 0, 8); + $to = substr(($dateRange['to'] ?? ''), 0, 8); // @todo fix relativeToAbsolute & add tests // relativeToAbsolute returns 8 char date strings // or 14 char date + time strings. diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index cdda9aa217..0e62e26514 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -373,7 +373,7 @@ class CRM_Utils_File { * stripped string */ public static function stripComments($string) { - return preg_replace("/^(#|--).*\R*/m", "", $string); + return preg_replace("/^(#|--).*\R*/m", "", ($string ?? '')); } /** diff --git a/CRM/Utils/String.php b/CRM/Utils/String.php index 93e96d05e0..4b230e1879 100644 --- a/CRM/Utils/String.php +++ b/CRM/Utils/String.php @@ -529,7 +529,7 @@ class CRM_Utils_String { */ public static function stripAlternatives($full) { $matches = []; - preg_match('/-ALTERNATIVE ITEM 0-(.*?)-ALTERNATIVE ITEM 1-.*-ALTERNATIVE END-/s', $full, $matches); + preg_match('/-ALTERNATIVE ITEM 0-(.*?)-ALTERNATIVE ITEM 1-.*-ALTERNATIVE END-/s', ($full ?? ''), $matches); if (isset($matches[1]) && trim(strip_tags($matches[1])) != '' @@ -639,7 +639,7 @@ class CRM_Utils_String { $_filter = new HTMLPurifier($config); } - return $_filter->purify($string); + return $_filter->purify($string ?? ''); } /** @@ -878,7 +878,7 @@ class CRM_Utils_String { return TRUE; } $len = strlen($fragment ?? ''); - return substr($string, 0, $len) === $fragment; + return substr(($string ?? ''), 0, $len) === $fragment; } /** @@ -895,7 +895,7 @@ class CRM_Utils_String { return TRUE; } $len = strlen($fragment ?? ''); - return substr($string, -1 * $len) === $fragment; + return substr(($string ?? ''), -1 * $len) === $fragment; } /** diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 1d8a67cb67..e0bcfc0117 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -805,7 +805,7 @@ class CRM_Utils_System { * The obscured credit card number. */ public static function mungeCreditCard($number, $keep = 4) { - $number = trim($number); + $number = trim($number ?? ''); if (empty($number)) { return NULL; } @@ -1831,7 +1831,7 @@ class CRM_Utils_System { '{sid}' => self::getSiteID(), '{baseUrl}' => $config->userFrameworkBaseURL, '{lang}' => $tsLocale, - '{co}' => $config->defaultContactCountry, + '{co}' => $config->defaultContactCountry ?? '', ]; return strtr($url, array_map('urlencode', $vars)); } diff --git a/api/v3/utils.php b/api/v3/utils.php index d1c05f1073..c2e25c92fd 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1617,7 +1617,7 @@ function _civicrm_api3_validate_fields($entity, $action, &$params, $fields) { case CRM_Utils_Type::T_MONEY: [$fieldValue, $op] = _civicrm_api3_field_value_check($params, $fieldName); - if (strpos($op, 'NULL') !== FALSE || strpos($op, 'EMPTY') !== FALSE) { + if (strpos(($op ?? ''), 'NULL') !== FALSE || strpos(($op ?? ''), 'EMPTY') !== FALSE) { break; } foreach ((array) $fieldValue as $fieldvalue) { -- 2.25.1