From: Seamus Lee Date: Thu, 28 Jul 2022 21:41:45 +0000 (+1000) Subject: [REF][PHP8.1] Another batch of fixes for passing in NULL values into functions that... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=08fb3005072e1081bcc43b34ea2fb4cd2d983907;p=civicrm-core.git [REF][PHP8.1] Another batch of fixes for passing in NULL values into functions that expect string|array parameters --- diff --git a/CRM/Contact/Page/View.php b/CRM/Contact/Page/View.php index 3069497500..e93d8925b8 100644 --- a/CRM/Contact/Page/View.php +++ b/CRM/Contact/Page/View.php @@ -162,7 +162,7 @@ class CRM_Contact_Page_View extends CRM_Core_Page { $this->set('contactType', $contactType); // note: there could still be multiple subtypes. We just trimming the outer separator. - $this->set('contactSubtype', trim($contactSubtype, CRM_Core_DAO::VALUE_SEPARATOR)); + $this->set('contactSubtype', trim(($contactSubtype ?? ''), CRM_Core_DAO::VALUE_SEPARATOR)); // add to recently viewed block $isDeleted = (bool) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'is_deleted'); diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index f184d19116..3b18216f3b 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -917,7 +917,7 @@ LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm $ufJoinDAO->module = $module; $ufJoinDAO->entity_id = $params['id']; $ufJoinDAO->find(TRUE); - $jsonData = json_decode($ufJoinDAO->module_data); + $jsonData = json_decode($ufJoinDAO->module_data ?? ''); if ($jsonData) { $json[$module] = array_merge((array) $jsonData->$module, $json[$module]); } diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index e54cd915fa..06829110fc 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -543,8 +543,8 @@ INNER JOIN civicrm_contribution con ON ( con.id = mp.contribution_id ) // we filter out null, '' and FALSE but not zero - I'm on the fence about zero. $overrides = array_filter([ 'is_test' => $inputOverrides['is_test'] ?? $recurringContribution['is_test'], - 'financial_type_id' => $inputOverrides['financial_type_id'] ?? $recurringContribution['financial_type_id'], - 'campaign_id' => $inputOverrides['campaign_id'] ?? ($recurringContribution['campaign_id'] ?? NULL), + 'financial_type_id' => $inputOverrides['financial_type_id'] ?? ($recurringContribution['financial_type_id'] ?? ''), + 'campaign_id' => $inputOverrides['campaign_id'] ?? ($recurringContribution['campaign_id'] ?? ''), 'total_amount' => $inputOverrides['total_amount'] ?? $recurringContribution['amount'], ], 'strlen'); diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index f687ac0a85..964340fb3b 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -353,7 +353,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $this->_paymentProcessorIDs = array_filter(explode( CRM_Core_DAO::VALUE_SEPARATOR, - CRM_Utils_Array::value('payment_processor', $this->_values) + ($this->_values['payment_processor'] ?? '') )); $this->assignPaymentProcessor($isPayLater); diff --git a/CRM/Contribute/Form/Task/TaskTrait.php b/CRM/Contribute/Form/Task/TaskTrait.php index 69bcf25b64..00a8bfcd20 100644 --- a/CRM/Contribute/Form/Task/TaskTrait.php +++ b/CRM/Contribute/Form/Task/TaskTrait.php @@ -122,6 +122,7 @@ trait CRM_Contribute_Form_Task_TaskTrait { $ids = $this->getSelectedIDs($this->getSearchFormValues()); if (!$ids) { $result = $this->getSearchQueryResults(); + $ids = []; while ($result->fetch()) { $ids[] = $result->contribution_id; } diff --git a/CRM/Core/CommunityMessages.php b/CRM/Core/CommunityMessages.php index 081457351c..ebf881cdbe 100644 --- a/CRM/Core/CommunityMessages.php +++ b/CRM/Core/CommunityMessages.php @@ -197,7 +197,7 @@ class CRM_Core_CommunityMessages { 'sid' => CRM_Utils_System::getSiteID(), 'baseUrl' => $config->userFrameworkBaseURL, 'lang' => $config->lcMessages, - 'co' => $config->defaultContactCountry, + 'co' => $config->defaultContactCountry ?? '', ]; $vars = []; foreach ($vals as $k => $v) { diff --git a/CRM/Core/Key.php b/CRM/Core/Key.php index 58b0a3912c..40708b180a 100644 --- a/CRM/Core/Key.php +++ b/CRM/Core/Key.php @@ -140,7 +140,7 @@ class CRM_Core_Key { public static function valid($key) { // ensure that key is an alphanumeric string of at least HASH_LENGTH with // an optional underscore+digits at the end. - return preg_match('#^[0-9a-zA-Z]{' . self::HASH_LENGTH . ',}+(_\d+)?$#', $key) ? TRUE : FALSE; + return preg_match('#^[0-9a-zA-Z]{' . self::HASH_LENGTH . ',}+(_\d+)?$#', ($key ?? '')) ? TRUE : FALSE; } /** diff --git a/CRM/Core/Page/Basic.php b/CRM/Core/Page/Basic.php index 32f912c964..52730c05d0 100644 --- a/CRM/Core/Page/Basic.php +++ b/CRM/Core/Page/Basic.php @@ -360,7 +360,7 @@ abstract class CRM_Core_Page_Basic extends CRM_Core_Page { $key = 'name'; } - if (trim($sort)) { + if (trim($sort ?? '')) { $object->orderBy($sort); } elseif ($key) { diff --git a/CRM/Core/Payment/Dummy.php b/CRM/Core/Payment/Dummy.php index d52efbb410..4b6735d819 100644 --- a/CRM/Core/Payment/Dummy.php +++ b/CRM/Core/Payment/Dummy.php @@ -332,7 +332,7 @@ class CRM_Core_Payment_Dummy extends CRM_Core_Payment { */ protected function getTrxnID() { $string = $this->_mode; - $trxn_id = CRM_Core_DAO::singleValueQuery("SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE '{$string}_%'"); + $trxn_id = CRM_Core_DAO::singleValueQuery("SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE '{$string}_%'") ?? ''; $trxn_id = str_replace($string, '', $trxn_id); $trxn_id = (int) $trxn_id + 1; return $string . '_' . $trxn_id . '_' . uniqid(); diff --git a/CRM/Core/Payment/PayPalImpl.php b/CRM/Core/Payment/PayPalImpl.php index f16370d206..1420b32600 100644 --- a/CRM/Core/Payment/PayPalImpl.php +++ b/CRM/Core/Payment/PayPalImpl.php @@ -566,7 +566,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $args['state'] = $params['state_province']; $args['countryCode'] = $params['country']; $args['zip'] = $params['postal_code']; - $args['desc'] = substr(CRM_Utils_Array::value('description', $params), 0, 127); + $args['desc'] = substr(($params['description'] ?? ''), 0, 127); $args['custom'] = $params['accountingCode'] ?? NULL; // add CiviCRM BN code @@ -1096,7 +1096,7 @@ class CRM_Core_Payment_PayPalImpl extends CRM_Core_Payment { $p = []; foreach ($args as $n => $v) { - $p[] = "$n=" . urlencode($v); + $p[] = "$n=" . urlencode($v ?? ''); } //NVPRequest for submitting to server diff --git a/CRM/Event/ActionMapping.php b/CRM/Event/ActionMapping.php index ae76bf3df2..c474a8dba6 100644 --- a/CRM/Event/ActionMapping.php +++ b/CRM/Event/ActionMapping.php @@ -140,7 +140,7 @@ class CRM_Event_ActionMapping extends \Civi\ActionSchedule\Mapping { $query['casContactIdField'] = 'e.contact_id'; $query['casEntityIdField'] = 'e.id'; $query['casContactTableAlias'] = NULL; - $query['casDateField'] = str_replace('event_', 'r.', $schedule->start_action_date); + $query['casDateField'] = str_replace('event_', 'r.', ($schedule->start_action_date ?? '')); if (empty($query['casDateField']) && $schedule->absolute_date) { $query['casDateField'] = "'" . CRM_Utils_Type::escape($schedule->absolute_date, 'String') . "'"; } diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index b48daaa4b3..9ab5ab46e4 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -1859,7 +1859,7 @@ WHERE civicrm_participant.contact_id = {$contactID} AND $details['eligible'] = TRUE; $details['status'] = $dao->status; $details['role'] = $dao->role; - $details['fee_level'] = trim($dao->fee_level, CRM_Core_DAO::VALUE_SEPARATOR); + $details['fee_level'] = trim(($dao->fee_level ?? ''), CRM_Core_DAO::VALUE_SEPARATOR); $details['fee_amount'] = $dao->fee_amount; $details['register_date'] = $dao->register_date; $details['event_start_date'] = $dao->start_date; diff --git a/CRM/Extension/Manager/Payment.php b/CRM/Extension/Manager/Payment.php index 0919690a6a..e5256278b6 100644 --- a/CRM/Extension/Manager/Payment.php +++ b/CRM/Extension/Manager/Payment.php @@ -56,18 +56,18 @@ class CRM_Extension_Manager_Payment extends CRM_Extension_Manager_Base { $dao->name = trim($info->name); $dao->description = trim($info->description); - $dao->user_name_label = trim($info->typeInfo['userNameLabel']); - $dao->password_label = trim($info->typeInfo['passwordLabel']); - $dao->signature_label = trim($info->typeInfo['signatureLabel']); - $dao->subject_label = trim($info->typeInfo['subjectLabel']); - $dao->url_site_default = trim($info->typeInfo['urlSiteDefault']); - $dao->url_api_default = trim($info->typeInfo['urlApiDefault']); - $dao->url_recur_default = trim($info->typeInfo['urlRecurDefault']); - $dao->url_site_test_default = trim($info->typeInfo['urlSiteTestDefault']); - $dao->url_api_test_default = trim($info->typeInfo['urlApiTestDefault']); - $dao->url_recur_test_default = trim($info->typeInfo['urlRecurTestDefault']); - $dao->url_button_default = trim($info->typeInfo['urlButtonDefault']); - $dao->url_button_test_default = trim($info->typeInfo['urlButtonTestDefault']); + $dao->user_name_label = trim($info->typeInfo['userNameLabel'] ?? ''); + $dao->password_label = trim($info->typeInfo['passwordLabel'] ?? ''); + $dao->signature_label = trim($info->typeInfo['signatureLabel'] ?? ''); + $dao->subject_label = trim($info->typeInfo['subjectLabel'] ?? ''); + $dao->url_site_default = trim($info->typeInfo['urlSiteDefault'] ?? ''); + $dao->url_api_default = trim($info->typeInfo['urlApiDefault'] ?? ''); + $dao->url_recur_default = trim($info->typeInfo['urlRecurDefault'] ?? ''); + $dao->url_site_test_default = trim($info->typeInfo['urlSiteTestDefault'] ?? ''); + $dao->url_api_test_default = trim($info->typeInfo['urlApiTestDefault'] ?? ''); + $dao->url_recur_test_default = trim($info->typeInfo['urlRecurTestDefault'] ?? ''); + $dao->url_button_default = trim($info->typeInfo['urlButtonDefault'] ?? ''); + $dao->url_button_test_default = trim($info->typeInfo['urlButtonTestDefault'] ?? ''); switch (trim($info->typeInfo['billingMode'])) { case 'form': @@ -86,8 +86,8 @@ class CRM_Extension_Manager_Payment extends CRM_Extension_Manager_Base { throw new CRM_Core_Exception(ts('Billing mode in info file has wrong value.')); } - $dao->is_recur = trim($info->typeInfo['isRecur']); - $dao->payment_type = trim($info->typeInfo['paymentType']); + $dao->is_recur = trim($info->typeInfo['isRecur'] ?? ''); + $dao->payment_type = trim($info->typeInfo['paymentType'] ?? ''); $dao->save(); } diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 24c2cfba7e..1d2ceafc81 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -1560,7 +1560,7 @@ ORDER BY civicrm_email.is_bulkmail DESC if (empty($defaults['from_email'])) { $defaultAddress = CRM_Core_BAO_Domain::getNameAndEmail(TRUE, TRUE); foreach ($defaultAddress as $id => $value) { - if (preg_match('/"(.*)" <(.*)>/', $value, $match)) { + if (preg_match('/"(.*)" <(.*)>/', ($value ?? ''), $match)) { $defaults['from_email'] = $match[2]; $defaults['from_name'] = $match[1]; } diff --git a/CRM/Member/ActionMapping.php b/CRM/Member/ActionMapping.php index e42add8682..24977439d9 100644 --- a/CRM/Member/ActionMapping.php +++ b/CRM/Member/ActionMapping.php @@ -82,7 +82,7 @@ class CRM_Member_ActionMapping extends \Civi\ActionSchedule\Mapping { $query['casContactTableAlias'] = NULL; // Leaving this in case of legacy databases - $query['casDateField'] = str_replace('membership_', 'e.', $schedule->start_action_date); + $query['casDateField'] = str_replace('membership_', 'e.', ($schedule->start_action_date ?? '')); // Options currently are just 'join_date', 'start_date', and 'end_date': // they need an alias diff --git a/CRM/Price/Form/Field.php b/CRM/Price/Form/Field.php index ed12cd3e77..cdfea438f8 100644 --- a/CRM/Price/Form/Field.php +++ b/CRM/Price/Form/Field.php @@ -473,7 +473,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form { // allow for 0 value. if (!empty($fields['option_amount'][$index]) || - strlen($fields['option_amount'][$index]) > 0 + strlen($fields['option_amount'][$index] ?? '') > 0 ) { $noAmount = 0; } diff --git a/CRM/Profile/Form.php b/CRM/Profile/Form.php index 74ed2ca620..2e0a437139 100644 --- a/CRM/Profile/Form.php +++ b/CRM/Profile/Form.php @@ -331,7 +331,7 @@ class CRM_Profile_Form extends CRM_Core_Form { } $this->_duplicateButtonName = $this->getButtonName('upload', 'duplicate'); - $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0)); + $gids = explode(',', (CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, FALSE, 0) ?? '')); if ((count($gids) > 1) && !$this->_profileIds && empty($this->_profileIds)) { if (!empty($gids)) { diff --git a/CRM/Profile/Form/Edit.php b/CRM/Profile/Form/Edit.php index c0f7ec2076..5f1d668b2d 100644 --- a/CRM/Profile/Form/Edit.php +++ b/CRM/Profile/Form/Edit.php @@ -183,8 +183,8 @@ SELECT module,is_reserved } // we do this gross hack since qf also does entity replacement - $this->_postURL = str_replace('&', '&', $this->_postURL); - $this->_cancelURL = str_replace('&', '&', $this->_cancelURL); + $this->_postURL = str_replace('&', '&', ($this->_postURL ?? '')); + $this->_cancelURL = str_replace('&', '&', ($this->_cancelURL ?? '')); // also retain error URL if set $this->_errorURL = $_POST['errorURL'] ?? NULL; diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 1649a77ff6..1b1d1788aa 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -5134,13 +5134,13 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a * is that we might print a bar chart as a pdf. */ protected function setOutputMode() { - $this->_outputMode = str_replace('report_instance.', '', CRM_Utils_Request::retrieve( + $this->_outputMode = str_replace('report_instance.', '', (CRM_Utils_Request::retrieve( 'output', 'String', CRM_Core_DAO::$_nullObject, FALSE, CRM_Utils_Array::value('task', $this->_params) - )); + ) ?? '')); // if contacts are added to group if (!empty($this->_params['groups']) && empty($this->_outputMode)) { $this->_outputMode = 'group'; diff --git a/CRM/Utils/Address.php b/CRM/Utils/Address.php index ff54a5b83b..56b79fa6ed 100644 --- a/CRM/Utils/Address.php +++ b/CRM/Utils/Address.php @@ -183,7 +183,7 @@ class CRM_Utils_Address { } // replacements in case of Custom Token - if (stristr($formatted, 'custom_')) { + if (stristr(($formatted ?? ''), 'custom_')) { $customToken = array_keys($fields); foreach ($customToken as $value) { if (substr($value, 0, 7) == 'custom_') { @@ -203,10 +203,10 @@ class CRM_Utils_Address { // the value is not empty, otherwise drop the whole {fooTOKENbar} foreach ($replacements as $token => $value) { if ($value && is_string($value) || is_numeric($value)) { - $formatted = preg_replace("/{([^{}]*)\b{$token}\b([^{}]*)}/u", "\${1}{$value}\${2}", $formatted); + $formatted = preg_replace("/{([^{}]*)\b{$token}\b([^{}]*)}/u", "\${1}{$value}\${2}", ($formatted ?? '')); } else { - $formatted = preg_replace("/{[^{}]*\b{$token}\b[^{}]*}/u", '', $formatted); + $formatted = preg_replace("/{[^{}]*\b{$token}\b[^{}]*}/u", '', ($formatted ?? '')); } } diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index f3add19251..98819be857 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -342,8 +342,8 @@ class CRM_Utils_Date { $fullWeekdayNames = self::getFullWeekdayNames(); $abbrWeekdayNames = self::getAbbrWeekdayNames(); - // backwards compatability with %D being the equivilant of %m/%d/%y - $format = str_replace('%D', '%m/%d/%y', $format); + // backwards compatibility with %D being the equivalent of %m/%d/%y + $format = str_replace('%D', '%m/%d/%y', ($format ?? '')); if (!$format) { $config = CRM_Core_Config::singleton(); diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index c697851787..aafffbd469 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -311,7 +311,7 @@ abstract class CRM_Utils_Hook { public function requireCiviModules(&$moduleList) { $civiModules = CRM_Core_PseudoConstant::getModuleExtensions(); foreach ($civiModules as $civiModule) { - if (!file_exists($civiModule['filePath'])) { + if (!file_exists($civiModule['filePath'] ?? '')) { CRM_Core_Session::setStatus( ts('Error loading module file (%1). Please restore the file or disable the module.', [1 => $civiModule['filePath']]), diff --git a/CRM/Utils/JS.php b/CRM/Utils/JS.php index 27c4d45245..6b5c03735c 100644 --- a/CRM/Utils/JS.php +++ b/CRM/Utils/JS.php @@ -147,7 +147,7 @@ class CRM_Utils_JS { } return $obj; } - $result = json_decode($js); + $result = json_decode($js ?? ''); if ($throwException && $result === NULL && $js !== 'null') { throw new CRM_Core_Exception(json_last_error_msg()); } diff --git a/CRM/Utils/JSON.php b/CRM/Utils/JSON.php index 5f3bcabd85..86b3f5d315 100644 --- a/CRM/Utils/JSON.php +++ b/CRM/Utils/JSON.php @@ -75,7 +75,7 @@ class CRM_Utils_JSON { // CRM-7130 --lets addslashes to only double quotes, // since we are using it to quote the field value. // str_replace helps to provide a break for new-line - $sOutput .= '"' . addcslashes(str_replace(["\r\n", "\n", "\r"], '
', $value[$element]), '"\\') . '"'; + $sOutput .= '"' . addcslashes(str_replace(["\r\n", "\n", "\r"], '
', ($value[$element] ?? '')), '"\\') . '"'; // remove extra spaces and tab character that breaks dataTable CRM-12551 $sOutput = preg_replace("/\s+/", " ", $sOutput); diff --git a/CRM/Utils/Mail/EmailProcessor.php b/CRM/Utils/Mail/EmailProcessor.php index 353ce5d1ca..cb72edc273 100644 --- a/CRM/Utils/Mail/EmailProcessor.php +++ b/CRM/Utils/Mail/EmailProcessor.php @@ -105,23 +105,23 @@ class CRM_Utils_Mail_EmailProcessor { } $config = CRM_Core_Config::singleton(); - $verpSeparator = preg_quote($config->verpSeparator); + $verpSeparator = preg_quote($config->verpSeparator ?? ''); $twoDigitStringMin = $verpSeparator . '(\d+)' . $verpSeparator . '(\d+)'; $twoDigitString = $twoDigitStringMin . $verpSeparator; $threeDigitString = $twoDigitString . '(\d+)' . $verpSeparator; // FIXME: legacy regexen to handle CiviCRM 2.1 address patterns, with domain id and possible VERP part - $commonRegex = '/^' . preg_quote($dao->localpart) . '(b|bounce|c|confirm|o|optOut|r|reply|re|e|resubscribe|u|unsubscribe)' . $threeDigitString . '([0-9a-f]{16})(-.*)?@' . preg_quote($dao->domain) . '$/'; - $subscrRegex = '/^' . preg_quote($dao->localpart) . '(s|subscribe)' . $twoDigitStringMin . '@' . preg_quote($dao->domain) . '$/'; + $commonRegex = '/^' . preg_quote($dao->localpart ?? '') . '(b|bounce|c|confirm|o|optOut|r|reply|re|e|resubscribe|u|unsubscribe)' . $threeDigitString . '([0-9a-f]{16})(-.*)?@' . preg_quote($dao->domain ?? '') . '$/'; + $subscrRegex = '/^' . preg_quote($dao->localpart ?? '') . '(s|subscribe)' . $twoDigitStringMin . '@' . preg_quote($dao->domain ?? '') . '$/'; // a common-for-all-actions regex to handle CiviCRM 2.2 address patterns - $regex = '/^' . preg_quote($dao->localpart) . '(b|c|e|o|r|u)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '$/'; + $regex = '/^' . preg_quote($dao->localpart ?? '') . '(b|c|e|o|r|u)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain ?? '') . '$/'; // a tighter regex for finding bounce info in soft bounces’ mail bodies - $rpRegex = '/Return-Path:\s*' . preg_quote($dao->localpart) . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '/'; + $rpRegex = '/Return-Path:\s*' . preg_quote($dao->localpart ?? '') . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain ?? '') . '/'; // a regex for finding bound info X-Header - $rpXheaderRegex = '/X-CiviMail-Bounce: ' . preg_quote($dao->localpart) . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain) . '/i'; + $rpXheaderRegex = '/X-CiviMail-Bounce: ' . preg_quote($dao->localpart ?? '') . '(b)' . $twoDigitString . '([0-9a-f]{16})@' . preg_quote($dao->domain ?? '') . '/i'; // CiviMail in regex and Civimail in header !!! // retrieve the emails @@ -145,16 +145,16 @@ class CRM_Utils_Mail_EmailProcessor { if ($usedfor == 1) { foreach ($mail->to as $address) { - if (preg_match($regex, $address->email, $matches)) { + if (preg_match($regex, ($address->email ?? ''), $matches)) { list($match, $action, $job, $queue, $hash) = $matches; break; // FIXME: the below elseifs should be dropped when we drop legacy support } - elseif (preg_match($commonRegex, $address->email, $matches)) { + elseif (preg_match($commonRegex, ($address->email ?? ''), $matches)) { list($match, $action, $_, $job, $queue, $hash) = $matches; break; } - elseif (preg_match($subscrRegex, $address->email, $matches)) { + elseif (preg_match($subscrRegex, ($address->email ?? ''), $matches)) { list($match, $action, $_, $job) = $matches; break; } @@ -162,13 +162,13 @@ class CRM_Utils_Mail_EmailProcessor { // CRM-5471: if $matches is empty, it still might be a soft bounce sent // to another address, so scan the body for ‘Return-Path: …bounce-pattern…’ - if (!$matches and preg_match($rpRegex, $mail->generateBody(), $matches)) { + if (!$matches and preg_match($rpRegex, ($mail->generateBody() ?? ''), $matches)) { list($match, $action, $job, $queue, $hash) = $matches; } // if $matches is still empty, look for the X-CiviMail-Bounce header // CRM-9855 - if (!$matches and preg_match($rpXheaderRegex, $mail->generateBody(), $matches)) { + if (!$matches and preg_match($rpXheaderRegex, ($mail->generateBody() ?? ''), $matches)) { list($match, $action, $job, $queue, $hash) = $matches; } // With Mandrilla, the X-CiviMail-Bounce header is produced by generateBody @@ -180,7 +180,7 @@ class CRM_Utils_Mail_EmailProcessor { if ($v_part instanceof ezcMailFile) { $p_file = $v_part->__get('fileName'); $c_file = file_get_contents($p_file); - if (preg_match($rpXheaderRegex, $c_file, $matches)) { + if (preg_match($rpXheaderRegex, ($c_file ?? ''), $matches)) { list($match, $action, $job, $queue, $hash) = $matches; } } @@ -188,7 +188,7 @@ class CRM_Utils_Mail_EmailProcessor { } // if all else fails, check Delivered-To for possible pattern - if (!$matches and preg_match($regex, $mail->getHeader('Delivered-To'), $matches)) { + if (!$matches and preg_match($regex, ($mail->getHeader('Delivered-To') ?? ''), $matches)) { list($match, $action, $job, $queue, $hash) = $matches; } } diff --git a/CRM/Utils/REST.php b/CRM/Utils/REST.php index c34b9e1be3..0848fdeac3 100644 --- a/CRM/Utils/REST.php +++ b/CRM/Utils/REST.php @@ -569,7 +569,7 @@ class CRM_Utils_REST { */ public function loadCMSBootstrap() { $requestParams = CRM_Utils_Request::exportValues(); - $q = $requestParams['q'] ?? NULL; + $q = $requestParams['q'] ?? ''; $args = explode('/', $q); // Proceed with bootstrap for "?entity=X&action=Y" diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index 746d578a33..1a1a6e9a67 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -549,7 +549,7 @@ class CRM_Utils_Rule { */ public static function cleanMoney($value) { // first remove all white space - $value = str_replace([' ', "\t", "\n"], '', $value); + $value = str_replace([' ', "\t", "\n"], '', ($value ?? '')); $config = CRM_Core_Config::singleton(); diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index f1e6cc6d02..43148fb6a2 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -1030,7 +1030,7 @@ class CRM_Utils_System { * @return string[] */ public static function explode($separator, $string, $limit) { - $result = explode($separator, $string, $limit); + $result = explode($separator, ($string ?? ''), $limit); for ($i = count($result); $i < $limit; $i++) { $result[$i] = NULL; } diff --git a/CRM/Utils/Type.php b/CRM/Utils/Type.php index 9eb9702f01..56e465cbac 100644 --- a/CRM/Utils/Type.php +++ b/CRM/Utils/Type.php @@ -421,8 +421,8 @@ class CRM_Utils_Type { case 'Date': case 'Timestamp': // a null timestamp is valid - if (strlen(trim($data)) == 0) { - return trim($data); + if (strlen(trim($data ?? '')) == 0) { + return trim($data ?? ''); } if ((preg_match('/^\d{14}$/', $data) || diff --git a/CRM/Utils/Verp.php b/CRM/Utils/Verp.php index 133a8bde38..bfcf7877eb 100644 --- a/CRM/Utils/Verp.php +++ b/CRM/Utils/Verp.php @@ -64,8 +64,8 @@ class CRM_Utils_Verp { $sdomain = $match[2]; preg_match('/(.+)\@([^\@]+)$/', $recipient, $match); - $rlocal = $match[1] ?? NULL; - $rdomain = $match[2] ?? NULL; + $rlocal = $match[1] ?? ''; + $rdomain = $match[2] ?? ''; foreach (self::$encodeMap as $char => $code) { $rlocal = preg_replace('/' . preg_quote($char) . '/i', "+$code", $rlocal); diff --git a/Civi/Api4/Provider/ActionObjectProvider.php b/Civi/Api4/Provider/ActionObjectProvider.php index 2a48d3165d..2b1b845bb1 100644 --- a/Civi/Api4/Provider/ActionObjectProvider.php +++ b/Civi/Api4/Provider/ActionObjectProvider.php @@ -175,7 +175,7 @@ class ActionObjectProvider implements EventSubscriberInterface, ProviderInterfac array_column(\CRM_Extension_System::singleton()->getMapper()->getActiveModuleFiles(), 'filePath') ); foreach ($locations as $location) { - $dir = \CRM_Utils_File::addTrailingSlash(dirname($location)) . 'Civi/Api4'; + $dir = \CRM_Utils_File::addTrailingSlash(dirname($location ?? '')) . 'Civi/Api4'; if (is_dir($dir)) { foreach (glob("$dir/*.php") as $file) { $className = 'Civi\Api4\\' . basename($file, '.php'); diff --git a/Civi/Test/DbTestTrait.php b/Civi/Test/DbTestTrait.php index 079bb8df6b..a16239c4a7 100644 --- a/Civi/Test/DbTestTrait.php +++ b/Civi/Test/DbTestTrait.php @@ -143,7 +143,7 @@ trait DbTestTrait { $expectedValue, $message ) { $value = \CRM_Core_DAO::getFieldValue($daoName, $searchValue, $returnColumn, $searchColumn, TRUE); - $this->assertEquals(trim($expectedValue), trim($value), $message); + $this->assertEquals(trim($expectedValue), trim($value ?? ''), $message); } /**