From d452367262b4ebdb3cb88e835204ea92b13e1b63 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 13 Apr 2022 13:47:43 +1200 Subject: [PATCH] ENH PHP 8.1 compatibility --- code/EditableSpamProtectionField.php | 12 ++++++------ code/Extension/FormSpamProtectionExtension.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/code/EditableSpamProtectionField.php b/code/EditableSpamProtectionField.php index a88b3e0..dfbdf41 100644 --- a/code/EditableSpamProtectionField.php +++ b/code/EditableSpamProtectionField.php @@ -130,13 +130,13 @@ class EditableSpamProtectionField extends EditableFormField */ public function onBeforeWrite() { - $fieldMap = json_decode($this->SpamFieldSettings, true); + $fieldMap = json_decode($this->SpamFieldSettings ?? '', true); if (empty($fieldMap)) { $fieldMap = array(); } foreach ($this->record as $key => $value) { - if (substr($key, 0, 8) === 'spammap-') { + if (substr($key ?? '', 0, 8) === 'spammap-') { $fieldMap[substr($key, 8)] = $value; } } @@ -176,7 +176,7 @@ class EditableSpamProtectionField extends EditableFormField // Generate field specific settings $mappableFields = FormSpamProtectionExtension::config()->get('mappable_fields'); - $mappableFieldsMerged = array_combine($mappableFields, $mappableFields); + $mappableFieldsMerged = array_combine($mappableFields ?? [], $mappableFields ?? []); foreach ($this->getCandidateFields() as $otherField) { $mapSetting = "Map-{$otherField->Name}"; $fieldOption = DropdownField::create( @@ -200,12 +200,12 @@ class EditableSpamProtectionField extends EditableFormField */ public function spamMapValue($mapSetting) { - $map = json_decode($this->SpamFieldSettings, true); + $map = json_decode($this->SpamFieldSettings ?? '', true); if (empty($map)) { $map = array(); } - if (array_key_exists($mapSetting, $map)) { + if (array_key_exists($mapSetting, $map ?? [])) { return $map[$mapSetting]; } return ''; @@ -235,7 +235,7 @@ class EditableSpamProtectionField extends EditableFormField $foundError = false; // field validate implementation may not add error to validator - if (count($errors) > 0) { + if (count($errors ?? []) > 0) { // check if error already added from fields' validate method foreach ($errors as $error) { if ($error['fieldName'] == $this->Name) { diff --git a/code/Extension/FormSpamProtectionExtension.php b/code/Extension/FormSpamProtectionExtension.php index 5ec74c5..fc2cfa9 100644 --- a/code/Extension/FormSpamProtectionExtension.php +++ b/code/Extension/FormSpamProtectionExtension.php @@ -73,7 +73,7 @@ class FormSpamProtectionExtension extends Extension $protector = self::config()->get('default_spam_protector'); } - if ($protector && class_exists($protector)) { + if ($protector && class_exists($protector ?? '')) { return Injector::inst()->create($protector); } else { return null;