Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH PHP 8.1 compatibility #82

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions code/EditableSpamProtectionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ protected function getCandidateFields()
*/
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;
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public function getCMSFields()

// 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(
Expand All @@ -200,12 +200,12 @@ public function getCMSFields()
*/
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 '';
Expand Down Expand Up @@ -235,7 +235,7 @@ public function validateField($data, $form)
$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) {
Expand Down
2 changes: 1 addition & 1 deletion code/Extension/FormSpamProtectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function get_protector($options = null)
$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;
Expand Down