Skip to content

Commit

Permalink
Merge pull request #209 from creative-commoners/pulls/2/php81
Browse files Browse the repository at this point in the history
ENH PHP 8.1 compatibility
  • Loading branch information
GuySartorelli authored Apr 26, 2022
2 parents 0a04e35 + 1b7dba1 commit d486842
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/StringTagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ protected function getOptions()
public function setValue($value, $source = null)
{
if (is_string($value)) {
$value = explode(',', $value);
$value = explode(',', $value ?? '');
}

if ($source instanceof DataObject) {
$name = $this->getName();
$value = explode(',', $source->$name);
$value = explode(',', $source->$name ?? '');
}

if ($source instanceof SS_List) {
Expand All @@ -270,7 +270,7 @@ public function setValue($value, $source = null)
$value = [];
}

return parent::setValue(array_filter($value));
return parent::setValue(array_filter($value ?? []));
}

public function saveInto(DataObjectInterface $record)
Expand Down Expand Up @@ -328,15 +328,15 @@ protected function getTags($term)
/** @var ArrayData $tag */
$tagValue = $tag->Value;
// Map into a distinct list (prevent duplicates)
if (stripos($tagValue, $term) !== false && !array_key_exists($tagValue, $items)) {
if (stripos($tagValue ?? '', $term ?? '') !== false && !array_key_exists($tagValue, $items ?? [])) {
$items[$tagValue] = [
'id' => $tag->Title,
'text' => $tag->Value,
];
}
}
// @todo do we actually need lazy loading limits for StringTagField?
return array_slice(array_values($items), 0, $this->getLazyLoadItemLimit());
return array_slice(array_values($items ?? []), 0, $this->getLazyLoadItemLimit());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/TagField.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function getSchemaDataDefaults()
);

if (!$this->getShouldLazyLoad()) {
$schema['options'] = array_values($this->getOptions()->toNestedArray());
$schema['options'] = array_values($this->getOptions()->toNestedArray() ?? []);
} else {
$schema['optionUrl'] = $this->getSuggestURL();
}
Expand Down Expand Up @@ -421,7 +421,7 @@ public function saveInto(DataObjectInterface $record)
}
}

$relation->setByIDList(array_filter($ids));
$relation->setByIDList(array_filter($ids ?? []));
}

/**
Expand Down Expand Up @@ -513,7 +513,7 @@ protected function getTags($term)
];
}

return array_values($items);
return array_values($items ?? []);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TagFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function compareExpectedAndActualTags(array $expected, TagFieldTestBlo
*/
protected function compareTagLists(array $expected, DataList $actualSource)
{
$actual = array_values($actualSource->map('ID', 'Title')->toArray());
$actual = array_values($actualSource->map('ID', 'Title')->toArray() ?? []);
sort($expected);
sort($actual);

Expand Down

0 comments on commit d486842

Please # to comment.